ios - 如何在 Swift 3 中检查当前 ViewController?
问题描述
我打开了ChatViewController
,我导航到了其他页面,然后我再次访问了,所以当我访问同一页面时,我ChatViewController
如何检查页面上的即时消息。ChatViewController
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
UserDefaults.standard.value(forKey: "ChatView")
print("view will appear called")
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(true)
UserDefaults.standard.object(forKey: "ChatView")
print("view will disappear called")
}
我需要设置任何UserDefaults
值或其他东西吗?有人可以帮助我吗?在此先感谢
解决方案
斯威夫特 5 和 iOS 15
if self.navigationController?.presentedViewController != nil &&
self.navigationController?.presentedViewController is ChatViewController {
return
}
推荐阅读
- performance - 如何在 LABVIEW 中快速将 U32 Image Array 解压成 RBG U8 Array
- android - 是否可以将文件共享到 Ionic 应用程序?
- python - 无法在 FLOW 中运行 Aimsun 示例
- mysql - 选择值为零的地方给出错误的结果
- android - 按钮状态drawable按下触发多个按钮
- time-complexity - 根据 theta 评估以下代码的时间复杂度
- android - 如何使用 Xposed 在 Android 中重定向 .so lib 的负载?
- java - 不支持您提供的 Scala AWS SDK S3 授权机制
- php - 我需要上传很多文件
- swiftui - 具有数据模型的结构,包括元组数组