0

ユーザーがボタンを押している時間をカウントし、この時間を秒単位で label.text ... (最大 10 秒) として表示しようとしていますが、すべて正常に動作していますが、label.textアクションの最後に更新します(ボタンとラベルは1つしかありません...)

私のヘッダー:

#import <UIKit/UIKit.h>
#import <CoreFoundation/CFData.h>
@interface TwisterViewController : UIViewController {
  UILabel *label;
  CFTimeInterval presstime;
}

@property(nonatomic,retain) IBOutlet UILabel *label;
-(IBAction) fingeron;

@end

私のMファイル

#import "TwisterViewController.h"
@implementation TwisterViewController
@synthesize label;
-(IBAction) fingeron
{
  int holdtime;
  presstime = CFAbsoluteTimeGetCurrent();
  holdtime = (int) (CFAbsoluteTimeGetCurrent() - presstime);
  NSString *holdtimetext; 
  while (holdtime <= 10) {
    holdtimetext = [NSString stringWithFormat:@"%d", holdtime];
    label.text = holdtimetext;
    holdtime = CFAbsoluteTimeGetCurrent() - presstime;
  }
  presstime = 0;
}

したがって、label.text は 9 秒間空であり、アクションの and では「10」と表示されます

4

1 に答える 1

0

このためのクレタタイマー

timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(fingerOn) userInfo:nil repeats: YES];

次に、独自のメソッドを使用します

 -(IBAction) fingeron
    {
        int holdtime;
    presstime = CFAbsoluteTimeGetCurrent();
    holdtime = (int) (CFAbsoluteTimeGetCurrent() - presstime);
    NSString *holdtimetext; 
    while(holdtime <= 10)
    {
        holdtimetext = [NSString stringWithFormat:@"%d", holdtime];
        label.text = holdtimetext;
        holdtime = CFAbsoluteTimeGetCurrent() - presstime;
    }
    presstime = 0;
}
于 2012-05-31T11:48:40.423 に答える