While attempting to use the action arguement of the constructor of a UIButtonBarItem
var done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: textField, action:"textFieldShouldReturn:textField")
I have tried a number of variations on this theme...
target: textField, action:"textFieldShouldReturn:textField:"
target: self, action:"textFieldShouldReturn:textField"
etc...
(textField is defined as a UITextField)
I get the following error at runtime:
[UITextField textFieldShouldReturn:textField]: unrecognized selector sent to instance
The target method should have the correct signature but I don't understand why the selector does not find the method.
func textFieldShouldReturn(textField: UITextField) -> Bool { //delegate method
Hopefully this is something simple that I am missing.
please be gentle... this is my first time 🙂
cheers
/chossy
Usually, calling UITextFieldDelegate method from your app code explicitly has no meaning. The method is called from within the UITextField, to customize its default behavior.
I guess you need and want to do something like this:
To setup UIBarButtonItem:
var done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action:"doneAction:")And in the same class, declare the action method:
func doneAction(sender: AnyObject) {
//Do something for textField
}You need to fill up `Do something for textField`, with what you actually intend to do.