在UITableView中发出警报的奇怪延迟

lit*_*ium 2 uitableview ios swift uialertcontroller

我有一些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
    })
Run Code Online (Sandbox Code Playgroud)

我的第一个警报有一些延迟,但它基本上没问题.但是,如果我试图点击下一个单元格,我必须等待几秒钟以显示我的警报.

所以,似乎我对访问我的数据没有任何问题(打印工作正常),但不知何故,在此之后需要几秒钟来显示UIAlertController.

我做错了什么?

Ras*_*n L 7

将其显示在主队列中:

DispatchQueue.main.async(execute: {
    self.present(alert, animated: true, completion: {
    //some code here
    })
})
Run Code Online (Sandbox Code Playgroud)