ios - 快速从弹出视图控制器中识别当前视图控制器
问题描述
假设我们有 2 个视图控制器
- FirstViewController.swift
- PopUpViewContraller.swift
PopUpViewContraller 已加载到 FirstViewController。现在如何从 PopUpViewContraller 调用 FirstViewController 中的函数。
解决方案
谢谢你回答我的问题。
最后,我得到了上述问题的解决方案。
我们可以使用通知中心来解决这个问题。
1)在弹出视图控制器()
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "botIsRemoved"), object: self)
2)在第一个视图控制器中
在 viewDidLoard() 里面
NotificationCenter.default.addObserver(self, selector: #selector(removeBotNow), name: NSNotification.Name(rawValue: "botIsRemoved"), object: nil)
并添加以下功能
@objc func removeBotNow(notification : Notification){
// your tasks
}
推荐阅读
- javascript - 带有隐式空值的 Ramda Curry
- javascript - 我不断收到此错误 Objects are not valid as a React child {} 如果您要呈现子集合,请改用数组
- javascript - 如何解决“无法读取未定义的属性‘定义’”?
- docker - Circle CI - 无法使用 Docker Compose 连接到 Redis 或 memcached,但我可以在本地计算机上这样做
- javascript - 同一页面上的多个网格的数据项选择未定义
- internationalization - google-libphonenumber 包不验证本地格式的中文电话号码
- java - BasicAuthenticationEntryPoint 未返回 WWW-Authenticate 标头
- r - 在 R 中使用 DBI 更新
- typescript - “对象属于‘未知’类型。” 在 RxJS 动作中
- php - Laravel 8 组件 @props 指令不起作用