I am setting a UIButton to the rightView of a UITextField. Furthermore, I am setting adding a target-action to the UIButton via
myButton.addTarget(self, action: "buttonPressed:", forControlEvents: .TouchUpInside)
I would like to know how I can access the UITextField from the method specified as buttonPressed where its method signature looks like:
func buttonPressed(sender: UIButton) {
}
I have tried
sender.superview as! UITextField
but I seem to be getting a nil.
Also, I am unable to use tags as it is already in use for another purpose.
EDIT:
For further information, myButton.addTarget() happens inside a UITableViewCell, which is why I don't have an outlet to the UITextField in the view controller.
Anyone have any ideas?
Your code is correct
I tried as follows and it is working for me
Custom
textField:Function
buttonPressed:Before Clicking
After Clicking on button of textField :
Hope you will find the problem.
Here is Xcode version 6.1. So, My example will be as per Swift 1.1.