Reputation: 31985
I try to alter my view controller within navigation controller when an user taps a button, so I declared the following code:
if standingsViewController == nil {
standingsViewController = StandingsViewController()
splitViewController!.delegate = standingsViewController
}
var vc = splitViewController!.viewControllers[1] as UINavigationController
vc.setViewControllers([standingsViewController], animated: true)
However, this causes an error: fatal error: attempt to bridge an implicitly unwrapped optional containing nil
on the last line.
UINavigationController
's setViewControllers: animated:
method is defined in Swift properly, so how can I fix up the problem?
For your information when I try to change it to [standingsViewController]!
, it didn't even pass the compiling because [AnyObject] is not identical to [AnyObject]!
.
I use Xcode 6.1 beta in Swift.
Upvotes: 1
Views: 7525
Reputation: 21003
Looks like you forgot to unwrap:
vc.setViewControllers([standingsViewController!], animated: true)
instead of
vc.setViewControllers([standingsViewController], animated: true)
Upvotes: 7