gpt4 book ai didi

ios - 不能做整数==比较

转载 作者:行者123 更新时间:2023-11-28 22:52:41 26 4
gpt4 key购买 nike

所以我有一个设置整数的方法:-(void)setcurrentviewfromint:(int)currentint{ 它位于一个名为 MyView 的类中。在我的 viewDidLoad 方法中,我调用它并将其设置为 1:currentview是int类型,在我的头文件中创建

- (void)viewDidLoad
{
[super viewDidLoad];
MyView *myview = [[MyView alloc]init];
[myview setcurrentviewfromint:1];
}

然后,在 MyView.m 中,我有这些类:

-(void)setcurrentviewfromint:(int)currentint{
currentview = currentint;
NSLog("currentviewis:%d",currentview);
[self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
NSLog(@"drawRectCalled");
if (currentview == 1) {
NSLog(@"do something here");
}
}

}

但是调试器打印出来:

2012-07-18 18:02:44.211 animation[76135:f803] currentviewis:1
2012-07-18 18:02:44.223 animation[76135:f803] drawRectCalled

但不打印“在这里做点什么”。知道为什么 currentview 不等于 1 吗?

最佳答案

首先,关于你的问题。currentview 是什么数据类型?其次,它看起来像 setcurrentviewfromint 中的 NSLog:永远不会被调用。如果它被调用,您会看到“currentviewis:1”,因此请确保它正确链接。

而且,我必须说,驼峰式!您的方法名称都是小写的,很难阅读。 :)

关于ios - 不能做整数==比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11551318/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com