Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with init() when subclassing BWWalkthrough #118

Open
wonathanjong opened this issue Jul 22, 2018 · 1 comment
Open

Problem with init() when subclassing BWWalkthrough #118

wonathanjong opened this issue Jul 22, 2018 · 1 comment

Comments

@wonathanjong
Copy link

While trying to implement the cocoa pod, BWWalkthrough, into my current project programmatically, I ran into a problem with the init functions/inheritance.

I tried to subclass BWWalkThroughViewController in my own class GetStartedViewController where I define buttons and pagecontrollers.

Here is the code from BWWalkThroughViewController which is a subclass of UIViewController:

class BWWalkThroughViewController: UIViewController {
    required public init?(coder aDecoder: NSCoder) {
        // Setup the scrollview
        scrollview.showsHorizontalScrollIndicator = false
        scrollview.showsVerticalScrollIndicator = false
        scrollview.isPagingEnabled = true
        super.init(coder: aDecoder)
    }

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
}

But when I try and subclass BWWalkthroughViewController in my own class I get errors saying "Ambiguous reference to member 'init(coder:)'" when calling super.init(nibName, bundle) and another error (Initializer does not override a designated initializer from its superclass) when I try to override the init(nibname, bundle):

import BWWalkthrough

class GetStartedViewController: BWWalkthroughViewController  {

required public init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

public init(){
    super.init(nibName: nil, bundle: nil) <== ERROR (Ambiguous reference to member 'init(coder:)')
}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) <== ERROR (Initializer does not override a designated initializer from its superclass) {
    super.init(nibName: nil, bundle: nil) <== ERROR (Ambiguous reference to member 'init(coder:)')
}
}

I've tried different variations of containing just the public init or just the override init and not both, so I included both to show the error.

Even when I use autocomplete to call super.init, all that shows up is the function with parameters of nscoder rather than with nibName and bundle.

Can someone please help me understand why this error is happening and how to fix it? I don't understand why I can't call super.init(nibName, bundle) or override the function.

Also, if anyone else has experience implementing BWWalkthrough programmatically and/or subclassing BWWalkthroughViewController without this init bug, any help would be appreciated :)

@jeanbaptistebeau
Copy link

Getting same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants