问题
有时在点击tableview上的一个cell后弹出UIAlertController,会发现有延迟的问题,或者点击没有反应,随便再点击一下才会弹出
问题解析
这种情况往往出现在 我们将 tableview 的 设置为 cell.selectionStyle = UITableViewCellSelectionStyleNone,是因为
点击事件发生后没有处理UI变动,或者加到其他线程中了,主线程经过一次(或多次)循环后才发现此需要刷新UI,然后才会刷新UI。
解决办法
1. 将 UIAlertController 放到 主线程中执行
func exit(){
DispatchQueue.main.async {
let alertController = UIAlertController(title: "提示",
message:"是否退出登录?", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
let okAction = UIAlertAction(title: "确定", style: .destructive, handler: {
action in
})
alertController.addAction(cancelAction)
alertController.addAction(okAction)
NavigatorService.modelToPage(alertController, animated: true, completion: {})
}
}
2. 去掉 cell.selectionStyle = .none 在点击事件里用 tableView.deselectRow(at: indexPath, animated: false )来处理