Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未显示UIAlertController_Ios_Swift_Mobile_Uialertview - Fatal编程技术网

Ios 未显示UIAlertController

Ios 未显示UIAlertController,ios,swift,mobile,uialertview,Ios,Swift,Mobile,Uialertview,这是我的ViewController.swift: import Intents class ViewController: UIViewController { @IBAction func getdbb() { db().getdb { (Db) in let alert1 = UIAlertController (title: "Random Trivia", message : Db, preferredStyle:

这是我的
ViewController.swift

import Intents

class ViewController: UIViewController {

    @IBAction func getdbb() {
            db().getdb { (Db) in
                let alert1 = UIAlertController (title: "Random Trivia", message : Db,  preferredStyle: .alert)
                alert1.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
                    let alert2 = UIAlertController(title: nil,  message: "Do you want to go to the next question?", preferredStyle: .alert)
                    alert2.addAction(UIAlertAction(title: "YES", style: .default, handler:{ action in self.getdbb() }))
                    alert2.addAction(UIAlertAction(title :"NO", style: .default, handler: nil ))

                }))
                self.present(alert1, animated: true, completion: nil)
                INInteraction(intent: GetQuestionIntent(), response: nil).donate(completion: nil)

        }

    }

}
我在main.storyboard中有一个查询按钮,它连接到
getdbb
函数,但是警报UI没有显示在模拟器中。这是我单击查询按钮时发生的情况(输出仅显示在Xcode中):


您没有在主线程中显示控制器,因此请尝试以下操作:

db().getdb { (Db) in

    DispatchQueue.main.async {
                let alert1 = UIAlertController (title: "Random Trivia", message : Db,  preferredStyle: .alert)
                alert1.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
                    let alert2 = UIAlertController(title: nil,  message: "Do you want to go to the next question?", preferredStyle: .alert)
                    alert2.addAction(UIAlertAction(title: "YES", style: .default, handler:{ action in self.getdbb() }))
                    alert2.addAction(UIAlertAction(title :"NO", style: .default, handler: nil ))

                }))
                self.present(alert1, animated: true, completion: nil)
                INInteraction(intent: GetQuestionIntent(), response: nil).donate(completion: nil)

        } 
}

您确定在主线程中执行了呈现UIAlert的闭包吗?在呈现警报的位置添加断点以确认(a)您在主线程上;(b)你一点也没有碰到那一行。
db().getdb()
的代码会很棒。检查你真正称之为闭包的地方。