我是 Objective C 的新手,来自 .NET 和 java 背景。
所以我需要异步创建一些 UIwebviews,我在我自己的队列上使用
dispatch_queue_t queue = dispatch_queue_create("myqueue", NULL);
dispatch_async(queue, ^{
// create UIwebview, other things too
[self.view addSubview:webView];
});
正如您想象的那样,这会引发错误:
bool _WebTryThreadLock(bool), 0xa1b8d70: 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...
那么如何在主线程上添加子视图呢?