我有一个在后台运行的 while 语句。
- (IBAction)startButton
{
[self performSelectorInBackground:@selector(Counter) withObject:nil];
.....
}
- (void) Counter
{
while (round) {
if (condition)
{
NSString *str;
str = [NSString stringWithFormat:@"%d",counter];
[self performSelectorOnMainThread:@selector(updateLabel:) withObject:str waitUntilDone:NO];
}
}
}
- (void)updateLabel: (NSString*) str
{
[self.label setText:str];
NSLog(@"I am being updated %@",str);
}
NSlog 让我得到正确的更新值,但标签永远不会更新。
我究竟做错了什么?
更新:
标签已连接,在 while 语句完成后,它会被更新。
我也初始化了标签。
- (void)viewDidLoad
{ [super viewDidLoad];
label.text = @"0";
}