如果声明无法正常工作 [英] If statement does not work properly

查看:90
本文介绍了如果声明无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

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。

But it never return first statement only return second statement,even is atim value is 0.

日志值:

MyAudioRecorder[2484:10703] value of atime is:0 

也试图把0而不是@0,仍然没有工作。

also tried to put 0 instead of @"0",still does not work.

推荐答案

if (atime==@"0")

比较 atime 内存地址常量字符串的地址 @0

Compares the memory address of atime with the address of constant string @"0".

if ([atime isEqualToString:@"0"]) 

比较存储在两个存储位置。

Compares the values that are stored in the two memory locations.

根据您的要求,您可以看到要比较值而不是存储位置。所以去第二个。

From your requirement it is seen that you want to compare the value not the memory location. So go for 2nd one.

这篇关于如果声明无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆