您最大的问题是您没有对警报按钮的处理程序执行任何操作.相反,您在发出警报后立即尝试执行弹出和解除.
移动代码以将控制器弹出到Ok按钮的警报处理程序中.
@IBAction func addButton(sender: AnyObject) { let alert = UIAlertController(title: "New Exercise Added", message: "\(name)", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Ok!!", style: UIAlertActionStyle.Default, handler: { self.navigationController?.popToRootViewControllerAnimated(true) // You only need the pop //self.dismissViewControllerAnimated(true, completion: {}) })) self.presentViewController(alert, animated: true, completion: nil) }
注意:我不熟悉Swift,所以语法可能会有点偏差.
您最大的问题是您没有对警报按钮的处理程序执行任何操作.相反,您在发出警报后立即尝试执行弹出和解除.
移动代码以将控制器弹出到Ok按钮的警报处理程序中.
@IBAction func addButton(sender: AnyObject) { let alert = UIAlertController(title: "New Exercise Added", message: "\(name)", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Ok!!", style: UIAlertActionStyle.Default, handler: { self.navigationController?.popToRootViewControllerAnimated(true) // You only need the pop //self.dismissViewControllerAnimated(true, completion: {}) })) self.presentViewController(alert, animated: true, completion: nil) }
注意:我不熟悉Swift,所以语法可能会有点偏差.