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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With