Reputation: 5732
Hey guys, can anyone explain me what (id)sender exactly means? I have seen it in so many actions and I don't know how to set this sender id.
- (IBAction)publishStream:(id)sender {
// do something
}
Furthermore, can you tell me how I can set this sender id in code?
Thanks, Cheers, doonot
Upvotes: 0
Views: 1663
Reputation: 125007
'id' is a type -- specifically, it's the type of an untyped pointer to an object. A variable of type 'id' can point to any objective-c object. In the case of an IBAction, it's common to have a single parameter named 'sender' that is the object sending the action. Any type of object can send the action, so the type of the 'sender' parameter is 'id'.
Upvotes: 5
Reputation: 8804
actually, sender is Control which invoke the event. like, if if you TouchInside the button and you had attached to your method. then that button will be sender here.
Upvotes: 0
Reputation: 1893
Well an ID is basically a blank type, so it's whatever type of object that called it, I don't believe that you actually set the sender, it's just the object. So say a UIButton called my IBAction, then whatever the UIButton happens to be will be the sender.
Upvotes: 2
Reputation: 62323
Using that you can re-direct several ui "widgets" to the same handler function. You can then use the "sender" to know which one generated the message.
Upvotes: 3