Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 views
in Technique[技术] by (71.8m points)

ios - 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
    }
}

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?

question from:https://stackoverflow.com/questions/38334776/fatal-error-use-of-unimplemented-initializer-in-custom-navigationcontroller

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...