ios - 如何呈现作为 mapView 委托的视图控制器,嵌入在 tabBar 控制器中?
问题描述
我有一个标签栏控制器,其中嵌入了三个 UIViewController,我们称它们为 ViewControllerA、ViewControllerB 和 ViewControllerC。我将我的 ViewControllerB 设置为 MKMapViewDelegate 子类化它,然后调用它的 viewDidLoad:
mapView.delegate = self
从我的 ViewControllerA 中,我以编程方式呈现第四个视图控制器,称为 ViewControllerD
let vcD = ViewControlledD()
vcD.modalPresentationStyle = .fullScreen
self.present(vcD, animated: true, completion: nil)
我在那里做我需要做的事情,然后我想将一些数据发送到嵌入在我的标签栏中的 ViewControllerB 并以编程方式呈现它。我该怎么做?我一直在尝试从我的 ViewControlledD 调用:
let vcB = ViewControlledB()
vcB.modalPresentationStyle = .fullScreen
vcB.myString = stringToPass
self.present(vcB, animated: true, completion: nil)
但是当我尝试它时,它会因错误而崩溃:
致命错误:在隐式展开可选值时意外发现 nil
指的是 mapView.delegate 所在的行。我怎样才能做到这一点?由于这是在应用程序中经常发生的转换,是否有任何解决方案可以在不实例化我的 ViewControllerB 的许多不同实例但始终引用同一个实例的情况下实现这一目标?
解决方案
推荐阅读
- reactjs - React 编译失败然后编译成功故障?
- python - Python - TKinter - 列 #0 中的树视图对齐文本
- c# - 为滚动条保留的空间截断文本
- sql - BigQuery 中的 Google Analytics:从同一查询中获取特定事件操作的总事件和总会话数
- javascript - 使用 node 和 ejs 在点击时显示表格
- reactjs - 从 props 更改自定义按钮的类型
- python - GradCAM 与分类不匹配
- javascript - 如何从模态窗口的 JSONPlaceholder 获取 ReactJS 应用程序中的照片 ID 以查看照片的详细信息?
- swift - SwiftUI:导航问题
- python-3.x - python 应用程序的exe文件创建数据库但在某些PC中不创建表