-1

在这:

-(IBAction)buttonClick: (id)sender {
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"Fo Sho?"
                                  delegate:self
                                  cancelButtonTitle:@"Cancel"
                                  destructiveButtonTitle:@"fo sho"
                                  otherButtonTitles:nil];
    [actionSheet showInView:self.view];
}

UIButton 将链接到这个“buttonClick”IBAction,但什么是“self”?

4

1 回答 1

1

self等价this于许多其他语言,例如 C++。换句话说,当您调用时[myString length],消息selflength的指针就是指向您的字符串的指针myString

-(void)logScore
{
    NSLog(@"%@ score is %d", self.name, self.score);
}

[player logScore];

在示例中,selfplayer对象。

于 2009-12-23T05:57:47.030 回答