0
在新线程结束时调用主线程将结果应用于UI是否很常见?我们不能应用“分离”线程的结果吗?例如,在示例代码ListAdder,我们使用:performElementInBackground之后调用performSelectorOnMainThread?
[self performSelectorInBackground:@selector(threadRecalculateNumbers:) withObject:immutableNumbers];
,并在功能上,我们再回到主线:
[self performSelectorOnMainThread:@selector(threadRecalculateDone:) withObject:totalStr waitUntilDone:NO];
和功能:
- (void)threadRecalculateDone:(NSString *)result
{
// The user interface is adjusted by a KVO observer on recalculating.
self.formattedTotal = result;
self.recalculating = NO;
}
谢谢
Paul
(这真的很难看出你的问题是什么......) – Infinite
“我们不能把我们的结果应用到”分离“线程吗?”不,用户界面不能从主线程以外的地方更新。 UIKit不是线程安全的。 – albertamg
@albertamg:感谢albert,所以我们在创建分离线程后总是调用主线程是有道理的。你能作为一个职位做出答案吗?非常感谢 – Paul