【发布时间】:2016-10-17 10:07:17
【问题描述】:
我有一些UITableView 的数据来自内部array。我想在点击时显示UIAlertController,但我遇到了非常奇怪的延迟。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("tapped \(dispatcher.conversations[indexPath.row].name)") //this one works fine, no problems here
let message = dispatcher.conversations[indexPath.row].desc + "\n\nDo you wanna play this?"
let alertname = dispatcher.conversations[indexPath.row].name
let alert = UIAlertController(title: alertname, message: message, preferredStyle: .alert)
let actionOK = UIAlertAction(title: "Play", style: UIAlertActionStyle.default, handler: { (action) in
//play the file
})
let actionCancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: { (action) in
//cancel the file
})
alert.addAction(actionOK)
alert.addAction(actionCancel)
self.present(alert, animated: true, completion: {
//some code here
})
我的第一个警报有一些延迟,但基本上没问题。但如果我试图点击下一个单元格,我必须等待几秒钟才能显示警报。
所以,我似乎在访问我的数据方面没有任何问题(打印工作正常),但不知何故,在那之后它需要几秒钟来显示 UIAlertController。
我做错了什么?
【问题讨论】:
-
你是在设备中测试还是在模拟器中测试?
-
两者(结果相同)。
-
不带插件的设备可以试试吗?
-
其实下面我们已经有了正确的答案。我试过了,它有效。
标签: ios swift uitableview uialertcontroller