Woo*_*ock 12 delegates ios swift
当像这样使用UIAlertController时:
var alert = UIAlertController(title: "Core Location",
message: "Location Services Disabled!",
preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default,
handler: nil))
self.navigationController.presentViewController(alert, animated: true,
completion: nil)
Run Code Online (Sandbox Code Playgroud)
我注意到警报视图的解雇似乎是自动完成的.不应该通过委托调用呈现ViewController来解雇呈现的 ViewController吗?
解雇被"包括"在presentViewController电话中.您不需要委托,因为您有完成块.在这个块中,您将通常放入委托回调中的内容放入,除了取消警报的调用.
就"最佳实践"而言,我注意到在许多API中,Apple用完成块替换了委托回调.Apple通常建议使用块语法.我推测这可能部分是因为它有助于将相关的代码段保持在一起.
| 归档时间: |
|
| 查看次数: |
11352 次 |
| 最近记录: |