If we use IBAction, we got the sender object right? If we also has an IBOutlet to that button, will that outlet point t开发者_如何学Co the same address as sender?
How do we test for equality then? Anyone doing it this way?
If you have a button in your XIB and connect that to your IBOutlet and its action to your IBAction, you will get the same pointer as sender argument in your IBAction. So you can simply use a pointer comparison: if (sender == myButton) { ... }
Using a tag is an alternative to using IBOutlets/variables in some cases (think buttons for a number pad). I think it's not as "obvious" or easily visible as an IBOutlet connection but I've used it for example when developing a number pad: each number button had a tag value that corresponded to the number of the button and all I had to do was evaluate the tag. Better than a dozen comparisons.
Sure, there's no reason you can't use the same action with multiple controls and compare the sender. That's pretty much the point of the sender being passed to actions.
精彩评论