I have a IBAction such as:
- (IBAction)showPicker:(id)sender;
How can I get the name of the control from the sender variable?
I am typically a c# coder so have tried the following to no avail
senderName = ((UIButton *)sender).name;
I need something more descriptive than the control id (not the button title either). I have 5 buttons all calling the same method. I need to determine which was clicked in order to perform the methods actions on the appropriate control. I.E I have an address picker method but want to populate 5 text fields with different details with each of 5 buttons. Just trying to keep the code tidy
N.B Originally I was planning on using the Interface Builders name field, but I’ve been advised (below) that this isn’t available at runtime.
You might want to look at using the tag property. It’s an integer rather than a name, but can be used to differentiate between two controls. It’s inherited from UIView so any control that’s sending an event should have it.
It’s editable in Interface Builder under View attributes.
It’s a property so it can be accessed programatically with the dot notation:
Or you can convert to a string as follows: