当用户点击按钮时,我尝试在导航控制器中更改视图控制器,因此我声明了以下代码:
if standingsViewController == nil {
standingsViewController = StandingsViewController()
splitViewController!.delegate = standingsViewController
}
var vc = splitViewController!.viewControllers[1] as UINavigationController
vc.setViewControllers([standingsViewController], animated: true)
但是,这会导致错误:最后一行上的
fatal error: attempt to bridge an implicitly unwrapped optional containing nil
。在Swift中正确定义了
UINavigationController
的setViewControllers: animated:
方法,那么如何解决该问题?供您参考,当我尝试将其更改为
[standingsViewController]!
时,它甚至没有通过编译,因为[AnyObject] is not identical to [AnyObject]!
。我在Swift中使用Xcode 6.1 beta。
最佳答案
好像您忘了打开包装:
vc.setViewControllers([standingsViewController!], animated: true)
代替
vc.setViewControllers([standingsViewController], animated: true)
关于ios - 如何在Swift中调用`setViewControllers:animation:`?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26886037/