2016-10-17 5 views
2

私はのデータを持つUITableViewをいくつか持っています。私はタップにUIAlertControllerを表示したいが、私は非常に奇妙な遅延を経験している。UITableViewでの警告の奇妙な遅延

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 
    }) 

私の最初のアラートには若干の遅延がありますが、大部分はOKです。しかし、次のセルをタップしようとすると、アラートが表示されるまで数秒待たなければなりません。

私のデータへのアクセスに問題はないようですが(印刷はうまくいきますが)、何とかUIAlertControllerを表示するには数秒かかりました。

どうしたのですか?代わりに

+0

あなたは、デバイスまたはシミュレータでテストしていますか? –

+0

(両方とも同じ結果)。 – lithium

+0

デバイスにプラグインなしで試すことができますか? –

答えて

5

それあなたのメインキューの現在:

DispatchQueue.main.async(execute: { 
    self.present(alert, animated: true, completion: { 
    //some code here 
    }) 
}) 
+0

うわー。ありがとう! 私は9分で回答を回答として受け入れるでしょう – lithium

+0

@lithiumを助けてうれしく思います –

関連する問題