开发者

What is "self" and how was the "view" property used?

In this:

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

A UIButton would be linked to this "buttonClick" IBAction but what is "self"?


self is the equivalent to this in many other languages such as C++. In other words when you call [myString length], the self pointer inside the length message is the pointer to your string named myString.

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

[player logScore];

In the example, self is the player object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜