背景:我想显示从UITableViewController(A)到UITableViewController(B)的模态segue,但我想显示一个NavigationBar为"Cancel"和"Save".
我做了什么:
在故事板中:
在A的ViewController中:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifer == "selectItem" {
if let indexPath = self.tableView.indexPathForSelectedRow() {
let destinationViewController = segue.destinationViewController as B
// Pass value from A to B
}
}
}
Run Code Online (Sandbox Code Playgroud)

错误:应用程序let destinationViewController = segue.destinationViewController as B因错误而崩溃swift_dynamicCastClassUnconditional.如果我没有将导航控制器嵌入到B中,程序就不会崩溃.但我真的需要一个导航栏.
有没有解决方案或其他方法来实现这一目标?谢谢!

PS:我试过在故事板中从对象库中拖动一个NavigationBar,但它错过了背景的一部分来覆盖状态栏...
UITableViewController在故事板中创建两个.UITableViewController(你想以模态方式呈现的那个),并将其嵌入到UINavigationController.UIBarButtonItem到UINavitionItem第二个UITableViewController.UITablViewCell你的第一个UITableViewControllerControl+Drag进入你的UINavigationController.Present Modally从下拉列表中的"Selecteion Segue"选项下选择" ".UITableViewController覆盖以下方法:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "identifier" {
let destination = segue.destinationViewController as UINavigationController
let bViewController = destination.topViewController as BViewController
// pass data
}
}
Run Code Online (Sandbox Code Playgroud)
以下是截图:

这应该做的,干杯!