【发布时间】:2017-08-20 22:04:24
【问题描述】:
我有一个没有按钮的 UIAlertController(我将此警报用作一些数据加载消息时请稍候),我在我的视图控制器的 viewDidLoad 函数中显示。显示警报后,我运行一个从数据库中检索信息的函数,一旦完成,我想解除警报,以便用户可以继续,但是警报似乎在运行后没有解除:
self.dismiss(animated: true, completion: nil)
我还尝试将我的 uialertcontroller 作为参数传递给函数并运行以下行但没有运气:
alertController.dismiss(animated: false, completion: nil)
编辑:这是我的 viewDidLoad 函数以及应该解除警报的函数
override func viewDidLoad() {
super.viewDidLoad()
let alertController = UIAlertController(title: "Loading", message:
"This might take a moment", preferredStyle: UIAlertControllerStyle.alert)
self.present(alertController, animated: true, completion: nil)
hideAlert(alert: alertController)
}
func hideAlert(alert: UIAlertController) {
let hideAlertController = { () -> Void in
alertController.dismiss(animated: false, completion: nil)
}
FIRDatabase.database().reference().child("info").observeSingleEvent(of: .value, with: { (dataSnapshot) in
DispatchQueue.main.async {
hideAlertController()
}
})
}
【问题讨论】:
标签: ios swift3 uialertcontroller dismiss