什么是“自我”,以及“视图”属性如何使用?
问题描述:
-(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
等效于许多其他语言(如C++)中的this
。换句话说,当您拨打[myString length]
时,length
消息中的self
指针是指向名为myString
的字符串的指针。
-(void)logScore
{
NSLog(@"%@ score is %d", self.name, self.score);
}
[player logScore];
在该示例中,self
是player
对象。
投票关闭,因为这是一个可能的重复:http://stackoverflow.com/questions/1950155/iphone-obj-c-where-does-this-view-property-come-from – 2009-12-23 05:55:49
确切的其他副本问题 – stefanB 2009-12-23 06:23:24
它也接近此:http://stackoverflow.com/questions/1883973/is-self-a-pointer – 2009-12-23 15:42:47