0

My function is this and it is called with a "done" UIBarButtonItem.

@IBAction func done(sender: UIBarButtonItem) {
    dismissViewControllerAnimated(true, completion: nil)
}

I have read multiple other questions/answers about a deleted instance or an old/extra connection in the Interface Builder or in the View Controller code. However, I only have this one function all properly connected without any extra lingering connections. How do I get rid of the "unrecognized selector sent to instance" error

Thanks in advance!

2
  • 1
    Try setting the selector programmatically. Commented Apr 25, 2016 at 7:09
  • The 'unrecognized selector' error comes with more information, would be helpful to post that. Also, comment the dismissViewControllerAnimated just to isolate the UIBarButtonItem, (I'm assuming 'self' is a ViewController, but just to be sure). Commented Apr 25, 2016 at 15:28

1 Answer 1

1

With the information provided in the question I suspect

There is unwanted connection left. To see that you can do:

1) Go to the IB and select the button.

2) Right click on the button and see all the actions. If you see any unwanted action delete it and try running again.

You can also do it programmatically

Set the target for UIBarButtonItem like this

var b = UIBarButtonItem(
    title: "Continue",
    style: .Plain,
    target: self,
    action: "sayHello:"
)

func sayHello(sender: UIBarButtonItem) {
}

If you dont want any parameters in the sayHello function, you can do it

var b = UIBarButtonItem(
    title: "Continue",
    style: .Plain,
    target: self,
    action: "sayHello"// Remove the colon
)

func sayHello() {
}

Let me know if it works for you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.