即使在dispatch_async上,UILabel也不会更新

任何理由为什么我的标签不会更新?

- (void)setLabel:(NSNotification*)notification { dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"setLabel"); [self.label setText:@"My Label"]; }); } 

我也尝试使用performSelectorOnMainThread无济于事。

请注意,setLabel出现在日志中。

附加信息:

我也有两个其他的function,只是用不同的文本做同样的事情。 另外两个函数没有dispatch_async,但都起作用。 另外,两个工作函数的通知是由NSURLConnection(本文中的方法#2)发送的。 虽然上面的非工作函数的通知是通过调用FBRequestConnection发送的(请参阅本文 )。

为了清楚起见,我的另外两个工作职能如下:

 - (void)setLabel2:(NSNotification*)notification { NSLog(@"setLabel2"); [self.label setText:@"My Label 2"]; } - (void)setLabel3:(NSNotification*)notification { NSLog(@"setLabel3"); [self.label setText:@"My Label 3"]; } 

是的,我尝试删除我的代码中的dispatch_async。 事实上,原来没有dispatch_async,因为其他两个工作。

如果你设置了一个断点,在你设置文本和打印描述self.label的地方是否显示文本已经改变? 如果是这样,它必须在这个方法触发后在其他地方重置。 如果self.label是零而不是你的问题