Replies

(id)sender is the object which sent the message to that selector. It's like in the delegate functions where you have the table view passed in to the cellForRowAtIndexpath function, etc.

You'd use this if you had 2 objects which were calling that selector and you wanted to distinguish between them. Of course, you could just use two different functions, but it's often cleaner and less duplication of code to use one function.

I recently read about this in an iphone development book and the example they use is a view with 2 buttons (left and right) and 1 label.

The controller only has one method -(IBAction) buttonPressed:(id)sender; which is used by both buttons. The sender object is used to get the button name and then updates the label with the string "<buttonName> was pressed".

so if u call your left button "left" and right button "right" you will get:
"Left button pressed" when button named left is pressed
"Right button pressed" when button name right is pressed

An action method doesnt have to pass the send object through, you can leave it off if you dont need it. It does come in usful in this example as now we only need one method to handle any button press. It saves us writing 2 methods rightButtonPressed and leftButtonPressed and hardcoding the new string to pass to the label.

This is my understanding and being a newbie myself i may be wrong, so please feel free to correct me anyone