Swift UIAlert立即自行消失

时间:2016-05-10 20:59:37

标签: ios swift

我已经在我的代码中全部使用了这个displayAlert功能,并且它已经完美地按预期工作了但是现在突然在我最新的视图控制器中它没有正常运行。

它会显示警告,然后在出现后会在一瞬间关闭它。

知道我做错了吗?

这是功能代码

   //This function displays an alert message
func displayAlert(title: String, msg: String){
    let alert = UIAlertController(title: title, message: msg, preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
        self.dismissViewControllerAnimated(true, completion: nil)

    }))

    //Support display in iPad
    alert.popoverPresentationController?.sourceView = self.view
    alert.popoverPresentationController?.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 1.0, 1.0)

    self.presentViewController(alert, animated: true, completion: nil)
}

这是按下按钮以显示UIAlert时执行的按钮操作。

     //Display alert message with avaiability per location
@IBAction func availability(sender: AnyObject) {
    self.displayAlert("Availability per location", msg: "Bellwood: September through April only\nBolingbrook: Sunday, Monday, Tuesday, Friday\nChicago: Sundays\nHighland Park: Saturdays\nVilla Park: Wednesday, Thursday, Friday, Saturday")
}

不确定我做错了什么。

这是我的后退按钮,它将解雇viewcontroller

 //Go back to previous view controller
@IBAction func back_btn(sender: AnyObject) {
     self.dismissViewControllerAnimated(true, completion: nil)
}

0 个答案:

没有答案