How can I tell programmatically if a IBAction has been called by code or by user action.
Eg
I have a method, -(IBAction)someMethodWithIts:(id)sender
which I have linked to a valueChanged on a UISegmentedControl.
It can be called by,
- User changing segment
- setting the selectedIndex in code
- calling
[self someMethodWithIts:foo];
Is there a way to distinguish if the call has come from the first way?
Cheers
Sam
If you can pass
nilas the sender (which is traditional) and use that to indicate it was sent programmatically, that’s ok. But anything else I believe is too fragile and you should break up the code like this:If you really want a sender, then you can do it this way:
But in general, if you want the IBAction to be different than programatic changes, then don’t wire programatic changes to the IBAction.