1

What is the difference between option 1 and 2? I am programatically setting up buttons and would like to know what is the advantage of one over the other or if they simply produce the same just different methods of reaching the goal.

Option 1 :

[signupButton addTarget:self action:@selector(signupButton:) forControlEvents:UIControlEventTouchUpInside];

Followed by the call:

-(IBAction)signupButton:(id)sender{

AND Option 2:

[signupButton addTarget:self action:@selector(signupButtonMethod) forControlEvents:UIControlEventTouchUpInside];

Followed by the call:

-(void)signupButtonMethod {
StuartM
  • 6,743
  • 18
  • 84
  • 160

1 Answers1

6

The first form includes the button as an argument to the method. This is useful when you wish to use the same action for more than one button. Then you can make use of the sender argument to know which button triggered the event.

The second form doesn't include any information about which button triggered the event. This is fine if the method is only used for a single button.

rmaddy
  • 314,917
  • 42
  • 532
  • 579