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()
的代码会很棒。检查你真正称之为闭包的地方。