相关:Is it ok to create a UIView on a background thread?
这个后台线程代码安全吗?
let viewController = MyViewController(nibName: nil, bundle: nil)
viewController.title = "My Title"
viewController.myProperty = true
dispatch_async(dispatch_get_main_queue(), {
self.navigationController?.pushViewController(viewController, animated: true)
})
最佳答案
@ozgur 的回答似乎已经过时了。如果您尝试在最新版本的 Xcode(撰写本文时版本 11.5)中从后台线程创建 UIViewController,那么您将收到以下错误:
-[UIViewController init] must be used from main thread only
关于ios - 在后台线程上创建 UIViewController 可以吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33511187/