ユーザーがボタンを押している時間をカウントし、この時間を秒単位で 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」と表示されます