所以我有一个prepareForSegue方法,像这样:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "fromEventTableToAddEvent" {
let addEventViewController: AddEventViewController = segue.destinationViewController as! AddEventViewController
addEventViewController.newTagArray = newTagArray
}
}
但是,在运行时,应用程序崩溃并且日志吐出了以下消息:
出现错误是因为addEventController嵌入在导航 Controller 中,但是我不确定如何设置segue,以便将destinationViewController设置为NavigationController,但还允许我将prepareForSegue方法中的变量传递给addEventController。
那么我将如何使用Swift做到这一点呢?
非常感谢您的帮助和时间。它可以帮助很多
最佳答案
您只需要访问导航 Controller 的topViewController,它将是AddEventViewController。这是代码:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "fromEventTableToAddEvent" {
let nav = segue.destinationViewController as! UINavigationController
let addEventViewController = nav.topViewController as! AddEventViewController
addEventViewController.newTagArray = newTagArray
}
}
关于ios - DestinationViewController Segue和UINavigationController swift ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28573635/