Iphone If语句不能正常工作

Iphone If语句不能正常工作,iphone,objective-c,ios,if-statement,Iphone,Objective C,Ios,If Statement,这是我的代码: NSString * atime = [NSString stringWithFormat:@"%@",[theDataObject.minuteArray objectAtIndex:indexPath.row]]; NSLog(@"value of atime is:%@",atime); if (atime==@"0") { NSString * timeStr = [NSString stringWithFormat:@"%@s",[theDataObjec

这是我的代码:

NSString * atime = [NSString stringWithFormat:@"%@",[theDataObject.minuteArray objectAtIndex:indexPath.row]];

NSLog(@"value of atime is:%@",atime);

if (atime==@"0") {

    NSString * timeStr = [NSString stringWithFormat:@"%@s",[theDataObject.secondArray objectAtIndex:indexPath.row]];

    cell.timeLabel.text = timeStr;
}
else {
    NSString * timeStr = [NSString stringWithFormat:@"%@m%@s",[theDataObject.minuteArray objectAtIndex:indexPath.row],[theDataObject.secondArray objectAtIndex:indexPath.row]];

    cell.timeLabel.text = timeStr;
}
但它从不返回第一条语句,只返回第二条语句,即使atim值为0

日志值:

MyAudioRecorder[2484:10703] value of atime is:0 
还尝试将0替换为@0,但仍然不起作用

尝试以下操作:

if ([atime isEqualToString : @" "]) {}
isEqualToString:->

返回一个布尔值,该值指示给定字符串是否等于使用基于Unicode的文本比较的接收方

讨论->此方法比较两个字符串时,如果单个Unicode相同,则字符串相等

更多信息,请访问apple

将atime的内存地址与常量字符串@0的地址进行比较

比较存储在两个内存位置中的值


从您的需求可以看出,您希望比较的是值,而不是内存位置。所以,选择第二个。

如果不是循环,那就必须是如果在我7年的职业生涯中,有很多人说如果循环。。。这是我第一次问你为什么说if循环???什么是if循环?你是说if语句吗?没问题。。。对你的问题加1作为奖励,你学到了一些东西:非常感谢你的+1和回答。
- (BOOL)isEqualToString:(NSString *)aString
if([atime isEqualToString:@"0"])
{
}
else
{
}
if (atime==@"0")
if ([atime isEqualToString:@"0"])