致命错误:在自定义navigationcontroller中使用未实现的初始化程序 [英] Fatal error: use of unimplemented initializer in custom navigationcontroller
问题描述
我正在创建一个自定义导航控制器。我有类似的东西:
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
}
}
我想测试一下,所以我创建了一个这样的CustomNavigationController:
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
执行 init(rootViewController :)
可能会调用 self.init(nibName:bundle :)
,但是你没有实现它会抛出错误。
UINavigationController
's implementation of init(rootViewController:)
probably calls self.init(nibName:bundle:)
which you haven't implemented so it throws the error.
除了已覆盖的初始值设定项外,还应覆盖 init(nibName:bundle)
。 init(nibName:bundle :)
是指定的初始化程序,而 init(rootViewController :)
是一个便利初始化程序。
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.
这篇关于致命错误:在自定义navigationcontroller中使用未实现的初始化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!