ios - ios - 如何知道第二个控制器是否被解雇?
问题描述
如果第二个控制器被解雇,是否可以在第一个控制器中处理和触发某些功能?
这是我从第一个控制器打开第二个控制器的代码
self.present(UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LockScreen") as UIViewController, animated: true, completion: nil)
这是我将控制器从第二个控制器解散到第一个控制器的代码
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true, completion: nil)
解决方案
在你的LockScreen
控制器中,声明一个关闭时要处理的闭包:
class LockScreen: UIViewController {
var onDismissHandler: (() -> ())?
func dismissController() {
self.dismiss(animated: true, completion: onDismissHandler)
}
}
然后当你展示时LockScreen
:
func onPresent() {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "LockScreen") as LockScreen
controller.onDismissHandler = { [weak self] in
// TODO: Do something when dismissed
}
self.present(controller, animated: true, completion: nil)
}
推荐阅读
- arraylist - 2 arraylist 是否相等
- java - 如何获取 Activity 中片段的当前更改状态?
- docker - 如何从 docker-compose 中的容器访问 localhost 应用程序
- php - Vimeo API - 无法启动上传
- mysql - 如何使用数组打印记录集?
- php - 在 where 子句中使用带有阿拉伯语单词的 codeigniter sqlsrv 时不返回任何行
- javascript - 如何在不触发更改事件的情况下替换表单?
- c# - 基本 System.Drawing.Color 类在多次迭代后仅返回一种颜色
- kubernetes - 为什么我不能通过端口转发器连接到 Pod?
- c# - 蓝牙连接读取失败,套接字可能关闭或超时,读取 ret:-1