0
我正在嘗試計算用戶將手指放在按鈕 上的時間,以秒爲單位顯示label.text ...(up到10秒) 一切工作正常,但label.text更新的動作 (我只有一個按鈕和一個標籤的結尾......)IBAction方法中的標籤文本不會更改
我的頭:
#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-file
#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秒,並在和動作的顯示「10」
我把它放在哪裏? couse它沒有做任何事情 – user1427972
試試這個ViewDidload或ViewWillAppear方法的ViewController –