2012-08-16 96 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,然后进行调试。