无法将类型的值转换为UINavigationController swift3

时间:2018-09-16 23:28:36

标签: ios swift3 delegates navigationcontroller

我收到以下强制转换错误(当我在模拟器[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?
...

1 个答案:

答案 0 :(得分:0)

只需阅读错误消息。你在说

segue.destination as! UINavigationController

但是此搜索的目的地不是UINavigationController的。