Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: use of unimplemented initializer in custom navigationcontroller

Tags:

ios

swift2

I'm creating a custom navigation controller. I have something like this:

public class CustomNavigationController: UINavigationController {      // MARK: - Life Cycle      override init(rootViewController: UIViewController) {         super.init(rootViewController: rootViewController)          delegate = self     }      required public init?(coder aDecoder: NSCoder) {         super.init(coder: aDecoder)         delegate = self     } } 

I wanted to test this out so I created a CustomNavigationController like this:

CustomNavigationController(rootViewController: ViewController()) 

When I run the app I get this:

fatal error: use of unimplemented initializer 'init(nibName:bundle:)' for class 'TestApp.CustomNavigationController' 

I don't see the problem, can anyone help me out?

like image 911
user1007522 Avatar asked Jul 12 '16 16:07

user1007522


1 Answers

UINavigationController's implementation of init(rootViewController:) probably calls self.init(nibName:bundle:) which you haven't implemented so it throws the error.

You should override init(nibName:bundle) in addition to the initializers you already override. init(nibName:bundle:) is a designated initializer while init(rootViewController:) is a convenience initializer.

like image 112
dan Avatar answered Sep 23 '22 14:09

dan