iOS PresentViewController彈出頁面延遲大忧饭,不彈出
場景
設置頁扛伍,當點擊底部cell,退出登錄時词裤,彈出提示框刺洒,退出登錄
let action = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let actionViewFirst = UIAlertAction(title: "取消", style: .cancel, handler: nil)
let actionViewSen = UIAlertAction(title: "確認退出", style: .destructive) { (alertAction) in
self.showSpinner()
// 請求退出登錄
self.viewModel?.getLogOut()
}
action.addAction(actionViewFirst)
action.addAction(actionViewSen)
self.present(action, animated: true, completion: nil)
結果
延遲比較大,有時彈不出來鳖宾,隨意點擊又彈出來
解決方法
將 self.present(action, animated: true, completion: nil)手動放入主線程中處理
DispatchQueue.main.async {
self.present(action, animated: true, completion: nil)
}
結論
present的方法,內(nèi)部可能是異步處理
最后編輯于 :
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者