无法从重复的NSTimer更新UILabel?
问题描述:
为什么不在iPhone上更新UILabel:“lbl”?无法从重复的NSTimer更新UILabel?
... 从方法中:
myTimer =[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(displayDataTimer) userInfo:nil repeats:YES];
...
-(void) displayDataTimer{
NSString *temp = [textField1 text];
[lbl setText:[NSString stringWithFormat:@"%d %d", j, genValue]];
//[self.view setNeedsDisplay:YES];
j++;
}
THX
答
确保您的方法烧制和您设置了出口到标签(命名为lbl),并且它是连线的,然后:
self.lbl.text = [NSString stringWithFormat:@"%d %d", j, genValue];
请注意[timer fire methods](http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Timers/Articles/usingTimers.html#//apple_ref/doc/uid/20000807-SW1)不应该无参数。它们应该如下所示:' - (void)displayDataTimer:(NSTimer *)tim;'定时器是否在主线程上创建?你确定火法正在运行吗? – 2012-01-09 20:31:40