【发布时间】:2011-12-14 14:21:52
【问题描述】:
在 buttonClicked 方法中,我想将 UILabel 中的文本颜色设置为黑色,等待三秒钟,然后将颜色设置为绿色。但是,标签永远不会变黑。该方法等待三秒钟,然后 UILabel 文本变为绿色。我认为使用 performSelectorOnMainThread 可以解决这个问题,但事实并非如此。代码如下。非常感谢,如果我遗漏了一些明显的东西,我们深表歉意。
乔恩·R.
-(void) buttonClicked: (id) sender
{
// (UILabel *) letterLabel is instance variable of TestProgramDelegate
[letterlabel performSelectorOnMainThread:@selector(setTextColor:) withObject:[UIColor blackColor] waitUntilDone:YES];
[NSThread sleepForTimeInterval:3];
[letterLabel performSelectorOnMainThread:@selector(setTextColor:) withObject: [UIColor greenColor] waitUntilDone:YES];
}
【问题讨论】: