为什么赢得这个if语句的工作?

时间:2012-08-16 01:47:40

标签: objective-c ios xcode cocoa if-statement

我有一个按钮可以将BOOL showSquare更改为YES

这是按钮的代码

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

这就是if语句

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

我做错了吗?

由于

2 个答案:

答案 0 :(得分: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));
}

同时检查您的财产是否已合成或具有吸气剂和固定剂。

答案 1 :(得分:0)

graphicsView不是零吗?

尝试将setter设置为showSquare,然后进行调试。