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

后端 未结 6 2052
甜味超标
甜味超标 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:33

    (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];
    }
    

提交回复
热议问题