rexis.cn

一张相片 一段故事

在UIViewController中用多线程更新UI的异常

without comments

在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在主线程中执行.

Written by 北

十一月 15th, 2009 at 9:06 上午

Posted in program

Leave a Reply