![](/img/trans.png)
[英]iOS Rolling out app updates. Keeping user data intact when DB update required
[英]IOS get notified when UI updates.
我有自定義鍵盤擴展名。 按下刪除鍵時調用此函數:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0),
{
for _ in 1..<50
{
(self.textDocumentProxy as UIKeyInput).deleteBackward()
}
print("Deletion End")
self.deleteCounter = 0
})
我不認為dispatch_async
是相關的,但我把它包括在內,只是因為它。
問題是,即使我的控制台在循環結束后打印“Deletion End”,文本字段的UI也不會更新,直到一兩秒鍾過去。
好像在呼喚
(self.textDocumentProxy as UIKeyInput).deleteBackward()
不立即刪除字符並更新UI。
如何在實際更新UI時通知我?
改變如下:
dispatch_async(dispatch_get_main_queue(),{
for _ in 1..<50
{
(self.textDocumentProxy as UIKeyInput).deleteBackward()
}
print("Deletion End")
self.deleteCounter = 0
})
說明:
UI必須在主線程中工作,因此當您使用后台隊列時,您始終必須在主隊列中分派UI更新。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.