2009-12-23 45 views
-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爲,但什麼是 「自我」?

+1

投票關閉,因爲這是一個可能的重複:http://stackoverflow.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://stackoverflow.com/questions/1883973/is-self-a-pointer – 2009-12-23 15:42:47

回答

1

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

相關問題