objective-cibactionsender

Objective C: what is a "(id) sender"?


In some IBAction I saw:

- (IBAction)pushButton:(id)sender;

This (id)sender when do I use it?


Solution

  • (id)sender is the object which sent the message to that selector.
    

    Code example:

    - (IBAction)submitButton:(id)sender {
        UIButton *button = (UIButton *)sender;
        [button setEnabled:NO];
        [button setTitle:@"foo" forState:UIControlStateDisabled];
    }