gso*_*lla 4 ios swift uialertcontroller
如果我打电话(在一个UIViewController)
alert.dismiss(animated: false, completion: nil)
print("executed after dismiss?")
Run Code Online (Sandbox Code Playgroud)
鉴于警报是先前提出的UIAlertController,dismiss方法是否同步执行?
我可以这样做:
alert.dismiss(animated: false, completion: nil)
let newAlert = UIAlertController(...)
present(newAlert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
在呈现时不必担心问题newAlert?
像大多数动画方法一样,当你解雇时,UIAlertController你只是让球滚动.视图控制器被异步关闭和删除.为了测试这个,我们可以使用这样的代码:
let alert = UIAlertController(title: "Oh No!", message: ":(", preferredStyle: UIAlertControllerStyle.alert)
self.present(alert, animated: true, completion: nil)
print(presentedViewController) // Optional(<UIAlertController: 0x7fefe901e670>)
alert.dismiss(animated: true, completion: nil)
print(presentedViewController) // Optional(<UIAlertController: 0x7fefe901e670>)
Run Code Online (Sandbox Code Playgroud)
如上所示,警报视图控制器不会立即作为呈现的视图控制器被移除.您可以在解除旧警报后立即显示新警报.但是,最佳做法是将第二个警报的代码放在第一个警报的完成处理程序中.viewDidDisappear在呈现的视图控制器上调用之后调用此完成处理程序.
| 归档时间: |
|
| 查看次数: |
1189 次 |
| 最近记录: |