4

Possible Duplicate:
Objective C: what is a “(id) sender”?

What is the (id)sender for in:

-(IBAction)action:(id)sender;

Thanks for your help!

Community
  • 1
  • 1
Jack Humphries
  • 13,056
  • 14
  • 84
  • 125
  • I didn't downvote all your questions (or even a single one). As for the flag, I was just looking through questions trying to find ones that popped up repeatedly. I'll even up vote this question if that pleases you. Sorry if my flagging your question made you think I was specifically targeting you in any way. – pasawaya Jul 21 '12 at 03:16
  • No problem. That's happened to me too. It's really annoying, so I understand why you were frustrated. – pasawaya Jul 21 '12 at 04:09

3 Answers3

4

It is whatever object has called the action method; e.g., a button.

You can use the id to check which of a set of buttons called the action, for instance.

Chris Gregg
  • 2,376
  • 16
  • 30
2

It identifies (and references) the control object that sent the action message.

csano
  • 13,266
  • 2
  • 28
  • 45
1

From the target-action design pattern:

The sender parameter is the control object sending the action message. When responding to an action message, you may query sender to get more information about the context of the event triggering the action message.

highlycaffeinated
  • 19,729
  • 9
  • 60
  • 91