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

后端 未结 6 2053
甜味超标
甜味超标 2020-11-29 05:40

In some IBAction I saw:

- (IBAction)pushButton:(id)sender;

This (id)sender when do I use it?

6条回答
  •  甜味超标
    2020-11-29 06:16

    It's part of the target-action mechanism of Cocoa, which is one way objects can communicate with each other. In response to an event (such as a mouse click), one object (usually a control of some kind) sends a message to another object. The sender is called, well, "sender", the receiver is the "target" and the message is the "action".

    You can use it in the target's message handler to get additional information about the action from the sender.

提交回复
热议问题