如何使MainThread等到某些异步操作完成?

B.S*_*.S. 5 multithreading asynchronous objective-c uitableview ios

我有UITableView一些内容,以异步方式加载.当用户旋转设备,我需要做[tableView reloadData]-willRotateToInterfaceOrientation方法.在我的情况下,ReloadData异步工作.

我知道reloadData在主线程中工作,但它会触发cellForRowAtIndexPath,它在我的情况下工作异步.

所以问题是如何使主线程等到UITableView's reloadData结束.

NSP*_*mer 2

如果您从 willRotateToInterfaceOrientation 调用 reloadData,那么它将在主线程上调用。事实上,UIView 不是线程安全的,只能从主线程处理(以防万一由于某种原因有人想从另一个线程调用 reloadData)。

我认为“异步”这个术语存在混淆。UI 委托的异步回调(例如 willRotateToInterfaceOrientation)在主线程上调用。异步并不一定意味着不同的线程(尽管“并行”异步运行确实如此)。

我建议阅读 Apple 的 NSRunLoop 文档。它是 iOS 应用程序运行方式不可或缺的一部分,也是应用程序程序员必须理解的。

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html