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.
精彩评论