UINavigationController is nil in swift 3

Ekra

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

enter image description here

Ekra

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.

edited at
0

Comments

0 comments
Login to comment

Related

UINavigationController return nil Swift

Swift 3 trying to create and use a UINavigationController programmatically

Swift 3 - override initializer for UINavigationController to set rootviewcontroller

hide backbutton embedded UINavigationController swift3

Swift 3 - Add navigation items to UINavigationController subclass

UINavigationController in Swift

UINavigationController returning nil

UINavigationController is nil after pop

URL is always nil in Swift 3

check if any property in an object is nil - Swift 3

Why is 'nil' not compatible with 'UnsafePointer<CGAffineTransform>' in Swift 3?

Dictionary value always nil in swift 3

Completion Block becomes nil in Swift 3

Nil element during .sorted in Swift 3

DateFormatter dateFromString Always Returns nil in swift 3

swift3 CoreData fetch returns nil

DestinationViewController Segue and UINavigationController swift

iOS rightBarButtonItem on UINavigationController in swift

Adding to existing UINavigationController in iOS / Swift

Why cgimage.copy always return nil in swift 3?

Why get nil when try to using dateFormatter in iOS Swift 3?

UserDefaults.standard set nil Error in XCode 8 and Swift 3

UiCollectionView must be initialized with a non-nil layout parameter Swift 3

Xcode8 Swift3 ImageURL returns nil

Swift 3 / iOS 10 / TodayExtension - UserDefaults always returns nil

swift3 iOS how to handle possible nil view in closure

Swift 3: Converting Data to String returns a nil value

How to detect if text in the text view is nil in all lines in Swift 3?

Swift 3 getting nil value in firebase while retrieving data