我正在尝试计算用户将手指按住按钮的时间,并将此时间以秒为单位显示为 label.text ...(最多 10 秒)一切正常,但 label.text在动作结束时更新(我只有一个按钮和一个标签......)
我的标题:
#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”