2012-08-16 95 views
0

我有一個按鈕來改變BOOLshowSquare等於YES爲什麼這個if語句不起作用?

這是按鈕

- (IBAction)Tap_Square:(id)sender { 
    [graphicsView setNeedsDisplay]; 
    [graphicsView setShowSquare:YES]; 
} 

的代碼,這就是if語句

if (showSquare) { 
    CGContextSetFillColorWithColor(context, white); 
    CGContextFillRect(context, CGRectMake(90, 90, 100, 100)); 
} 

我在幹嘛有問題?

感謝

+0

你的財產在哪裏申報? – DrummerB 2012-08-16 01:49:32

+0

確保'showSquare'爲YES,並在'[graphicsView setShowSquare:YES]'上設置斷點以確保它被執行 – 2012-08-16 01:49:38

+0

嘗試將yes更改爲true? – alpera 2012-08-16 01:51:14

回答

0

如果你想與屬性而不是實例變量的工作,最好是使用存取方法來獲取和設置它的值。

// use self.showSquare if you call this code in graphicsView instance 
if (self.showSquare) { 
    CGContextSetFillColorWithColor(context, white); 
    CGContextFillRect(context, CGRectMake(90, 90, 100, 100)); 
} 

同時檢查您的財產是否合成或有getter和setter。

+0

...除非你使用XCode 4.4,在這種情況下,你不再需要綜合你的屬性。 – 2012-08-16 07:26:42

0

graphicsView不是零?

嘗試將setter設置爲showSquare,然後進行調試。