ios - 无法将数据传递到嵌入在导航栏中的视图控制器
问题描述
我想将一些数据传递给嵌入在导航栏中的 ApplicationsViewController,因此出现错误:无法转换类型“UINavigationController”的值
我无法理解如何实现它。非常感谢您的帮助。谢谢你。
解决方案
原因是您不能将数据直接传递到ApplicationViewController
segueInboxViewController
的目的地是UINavigationController
.
因此,首先您需要访问UINavigationController
,然后ApplicationsViewController
从堆栈中访问。
试试下面的代码:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goToApplications" {
if let navigation = segue.destination as? UINavigationController, let applicationVC = navigation.topViewController as? ApplicationsViewController {
applicationVC.id = "RGB"
}
}
}
推荐阅读
- java - 在多态中使用 ArrayList
- php - 保护 WordPress 主题文件夹免受插件访问
- c# - 使用 ASP.NET C# 的带有格式化文本 HTML 的 GridView
- javascript - React 中基于 Material UI 中 IconButton 组件的 onClick 属性的条件渲染
- c# - 找不到方法:'System.Threading.Tasks.Task`1
- google-cloud-platform - 用于 SQL 分析的 Google Cloud Jupyter Notebook
- python - 需要一个缩进块,python
- heroku - Heroku 域连接失败
- python - 拒绝在新目录中创建文件的权限
- r - 如何让 R 和不存在或空数据