Ios 如何在Swift中调用`setViewControllers:animated:`?
当用户点击按钮时,我尝试在导航控制器中更改我的视图控制器,因此我声明了以下代码:Ios 如何在Swift中调用`setViewControllers:animated:`?,ios,swift,uinavigationcontroller,Ios,Swift,Uinavigationcontroller,当用户点击按钮时,我尝试在导航控制器中更改我的视图控制器,因此我声明了以下代码: if standingsViewController == nil { standingsViewController = StandingsViewController() splitViewController!.delegate = standingsViewController } var vc = splitViewController!.viewControllers[1] as UINav
if standingsViewController == nil {
standingsViewController = StandingsViewController()
splitViewController!.delegate = standingsViewController
}
var vc = splitViewController!.viewControllers[1] as UINavigationController
vc.setViewControllers([standingsViewController], animated: true)
但是,这会导致一个错误:致命错误:尝试桥接最后一行包含nil的隐式未包装可选项
UINavigationController的setViewControllers:animated:method在Swift中定义正确,那么如何解决这个问题呢
当我尝试将其更改为[StandingViewController]时,请参考!,它甚至没有通过编译,因为[AnyObject]与[AnyObject]不相同
我在Swift中使用的是Xcode 6.1测试版。看起来您忘记打开了:
vc.setViewControllers([standingsViewController!], animated: true)
而不是
vc.setViewControllers([standingsViewController], animated: true)
看起来你忘记打开了:
vc.setViewControllers([standingsViewController!], animated: true)
而不是
vc.setViewControllers([standingsViewController], animated: true)
在调用SetViewController之前,能否检查StandingViewController是否为零?看起来是的。啊,是零。看起来是因为我定义了弱var standingsViewController:standingsViewController!在类的顶部,而不仅仅是var。我很感激。在调用SetViewController之前,您能检查StandingViewController是否为nil吗?看起来是的。啊,是零。看起来是因为我定义了弱var standingsViewController:standingsViewController!在班上名列前茅,而不仅仅是var。我很感激。