Mar*_*dic 1 storyboard ios swift uialertcontroller
我有一个警报,在显示警报后,我想呈现一个不同的viewFinder.触发doSomething()函数,打印"TEST",但不显示新的取景器.我错过了什么?
警报
let alert = UIAlertController(title: "Sorry", message: "Booked out.",
preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style:
UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: self.doSomething)
Run Code Online (Sandbox Code Playgroud)
content func doSomething()
print("TEST")
let details = storyboard?.instantiateViewController(withIdentifier: "ViewLimo2")
details?.transitioningDelegate = slideAnimatorRight
present(details!, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
取消视图控制器时,视图控制器上的完成块不会触发.它在视图控制器完成呈现时触发(例如,它已完成viewDidAppear).
老实说,我希望这会崩溃,因为你正试图在警报仍然存在时出现.
在任何情况下,您需要等到解除UIAlertController之前尝试呈现下一个View Controller.
您可以在操作的处理程序中执行此OK操作:
let alert = UIAlertController(title: "Sorry", message: "Booked out.",
preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style:
UIAlertActionStyle.default, handler: doSomething))
self.present(alert, animated: true, completion: nil)
...
func doSomething(action:UIAlertAction) {
/// present the next VC here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
390 次 |
| 最近记录: |