// 1.NSThread
[self performSelectorOnMainThread:@selector(updateUI) withObject:nil waitUntilDone:NO];
- (void)updateUI {
// UI更新代码
self.alert.text = @"Thanks!";
}
// 2.NSOperationQueue
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
// UI更新代码
self.alert.text = @"Thanks!";
}];
// 3.GCD
dispatch_async(dispatch_get_main_queue(), ^{
// UI更新代码
self.alert.text = @"Thanks!";
});
http://blog.csdn.net/cordova/article/details/54933729
本文介绍了三种在iOS应用中更新主线程UI的方法:使用NSThread的performSelectorOnMainThread、NSOperationQueue的mainQueue以及Grand Central Dispatch (GCD) 的dispatch_async。这三种方式都能确保UI更新操作在主线程上执行。

1687

被折叠的 条评论
为什么被折叠?



