在UIViewController中用多线程更新UI的异常
在UIViewController中用多线程时,如果该线程方法中有更新UI操作的话,会抛出如下错误:
Tried to obtain the web lock from a thread other than the main thread or the web thread.
This may be a result of calling to UIKit from a secondary thread. Crashing now…
貌似是因为UIKit是非线程安全的,所以更新UI只能在主线程中操作,解决的办法:
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
用该方法指定要执行的UI更新Method在主线程中执行.