ios - 无法将类型值转换为 UINavigationController swift3
问题描述
我收到以下转换错误(当我单击模拟器 [NavigationController] 中的“+”按钮时)并且无法弄清楚原因。我正在使用 Swift3。谢谢你的帮助!
MainVC.swift
protocol AddTaskDelegate: class {
func saveTask(by controller: AddVC, with data: [String:String])
}
class MainVC: UIViewController {
// all tasks from the database
var tasks = [ToDoListTasks]()
@IBOutlet weak var table: UITableView!
// connect with Core Data
let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
...
// prepare segue to send data
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "AddSegue" {
let navigationController = segue.destination as! UINavigationController
let childViewController = navigationController.topViewController as! AddVC
childViewController.delegate = self as! AddTaskDelegate
}
}
}
AddVC.swift
class AddVC: UIViewController {
weak var delegate: AddTaskDelegate?
...
解决方案
只需阅读错误消息。你是说
segue.destination as! UINavigationController
但是这个 segue 的目的地不是UINavigationController。
推荐阅读
- swift - 将 TableView 的拖放 API 与底层值类型数据对象一起使用
- mysql - 从不同的表中选择列
- corda - 在 Corda 中使用 TestContainers 进行 API 测试
- .net - 如何在 .net5 中使用 EF6?
- asp.net - 在 Web 应用程序 ASP.NET 中实现 SAML2\Shibboleth
- reactjs - 如何在图像上添加材质 ui 文本字段?
- flutter - 颤动如何转换地图中的列表
- c# - Test.Program 的类型初始化程序引发异常
- html - CSS 关键帧闪光效果在 Chrome 中有效,但在 Firefox 中无效?
- javascript - 如何在某个点(75%)开始动画?