当我在后台线程上显示 AletView 时,为什么 UI 挂起?
Why does the UI hang when I show AletView on background thread?
我已经显示了一个线程中的 UIAlertView
,但是 UI 挂起,然后在 2-3 秒后显示 UIAlertView
。
我可以使用 dispatch_async(dispatch_get_global_queue...
或 performSelectorOnMainThread
来解决这个问题。
我想知道为什么当我们在后台线程上显示任何 UIAlertView
时 UI 挂起。
在 iOS 上,所有 UI 操作都必须在主线程上执行 ,你不能有 UI 操作(例如如在后台线程上显示 UIAlertView
)。这也是 performSelectorOnMainThread:
解决问题的原因。
这是一个不错的blog post on the topic and a link to the docs。
我已经显示了一个线程中的 UIAlertView
,但是 UI 挂起,然后在 2-3 秒后显示 UIAlertView
。
我可以使用 dispatch_async(dispatch_get_global_queue...
或 performSelectorOnMainThread
来解决这个问题。
我想知道为什么当我们在后台线程上显示任何 UIAlertView
时 UI 挂起。
在 iOS 上,所有 UI 操作都必须在主线程上执行 ,你不能有 UI 操作(例如如在后台线程上显示 UIAlertView
)。这也是 performSelectorOnMainThread:
解决问题的原因。
这是一个不错的blog post on the topic and a link to the docs。