In my main storyboard I have 1 Navigation controller and subsequent swift file NavigationCtr.swift.
The viewController is in different xib.
Now I want to push my viewController from the NavigationCtr class.
let vcFirst = FirstViewController(nibName: "FirstViewController", bundle: nil)
self.navigationController!.pushViewController(vcFirst, animated: true)
I am getting a exception
fatal error: unexpectedly found nil while unwrapping an Optional value
So when I trying to print from viewDidLoad
print(self.navigationController)
in NavigationCtr.swift class it is giving nil. So nothing works
I created a new project in objective C and it works fine. Attached the storyboard image Any hint in the direct direction is highly appreciated. Note : - I am new to swift
the main issue was using the self.navigationController
As my storyboard only had navigationController I should just self keyword. as below
let vcFirst = FirstViewController(nibName: "FirstViewController", bundle: nil)
self.pushViewController(vcFirst, animated: true)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments