什么是“自我”,以及“视图”属性如何使用?

问题描述:

在此:什么是“自我”,以及“视图”属性如何使用?

-(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为,但什么是 “自我”?

+1

投票关闭,因为这是一个可能的重复:http://*.com/questions/1950155/iphone-obj-c-where-does-this-view-property-come-from – 2009-12-23 05:55:49

+0

确切的其他副本问题 – stefanB 2009-12-23 06:23:24

+0

它也接近此:http://*.com/questions/1883973/is-self-a-pointer – 2009-12-23 15:42:47

self等效于许多其他语言(如C++)中的this。换句话说,当您拨打[myString length]时,length消息中的self指针是指向名为myString的字符串的指针。

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

[player logScore]; 

在该示例中,selfplayer对象。

+0

在我的具体例子呢?它会是UIButton或UIView或UIViewController吗? – Devoted 2009-12-23 07:06:35

+1

如果buttonClick是View控制器的方法,那么它将是视图控制器。 如果buttonClick是View的方法,那么它将被视图。 – 2009-12-23 09:00:05

+1

这将是您向我们展示的#buttonClick:'-Method属于的类的一个实例。最有可能的是一个'UIViewController',但是因为你没有向我们展示更多的代码,这只是一个猜测 – nils 2009-12-23 09:06:50