【发布时间】:2012-07-13 13:40:52
【问题描述】:
我正在尝试根据两个整数的值执行逻辑。在这里我定义了我的整数,我也有 NSLog,所以我可以在运行代码时查看值是否正确:
int theHikeFlag = (int)[theNewHikeFlag objectAtIndex:(theID-1)];
NSLog(@"theHikeFlag: %@",theHikeFlag);
int fromTheDB = [self.detailItem hikeFlag];
NSLog(@"fromTheDB: %d",fromTheDB);
这是逻辑:
if (theHikeFlag==1) {
hikeString=@"You have";
}
else if (theHikeFlag==0) {
hikeString=@"You have not";
}
else {
if (fromTheDB==1) {
hikeString=@"You have";
}
else {
hikeString=@"You have not";
}
}
作为此代码如何工作的示例。当theHikeFlag=1 和fromTheDB=0 时,代码绕过if 和else if 直接进入else 并设置hikeString="You have not"。这意味着我的结果与 theHikeFlag 无关,并且基于 fromTheDB 整数。
【问题讨论】:
-
如果
theNewHikeFlag是NSArray那些存储在那里的东西是NSObject*s 你不应该将它们转换为基本数据类型。如果它们存储为NSNumber*s,则将它们转换为这样,然后取intValue -
你能告诉我你在运行所有可能的测试用例时得到的日志输出吗?当你(int)投射 theNewHikeFlag 中的任何内容时,我感觉发生了一些奇怪的事情
标签: objective-c xcode xcode4.3