Я хочу знать, почему я не могу запустить действие кнопки во вторичном потоке (см. Ниже код вторичного потока), когда я делаю так, приложение разрывается и показывает мне следующее сообщение об ошибке.
NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(insertdata) object:nil];
[thread start];
void _WebThreadLockFromAnyThread(bool), 0x6a8cfe0: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.
bool _WebTryThreadLock(bool), 0x6a8cfe0: 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...
1 WebThreadLock
2 -[UIFieldEditor setText:andSetCaretSelectionAfterText:]
3 -[UITextField setText:]
4 -[XYZ reset]
5 -[XYZ insertdata]
6 -[NSThread main]
7 __NSThread__main__
8 _pthread_start
9 thread_start
Но когда я меняю поток на основной поток (см. Код основного потока ниже), я не вижу никакого сбоя, и мое приложение работает отлично.Может кто-нибудь объяснить, в чем разница, почему я не могу запустить дополнительный поток действий.
[self performSelectorOnMainThread:@selector(insertdata) withObject:nil waitUntilDone:NO];
Спасибо.