Mat*_*ann 0 c++ if-statement objective-c
我正在尝试使用多个条件创建多个if语句.如果我运行代码它工作正常但它永远不会改变输出.我总是得到第二个声明> = 29.这是我的代码.
if (label.text <= @"30")
{label.text = @"Text";}
else if (label.text >= @"29")
{label.text = @"Text";}
else if (label.text >= @"19")
{label.text = @"Text";}
else if (label.text >= @"10")
{label.text = @"Text";}
else if (label.text = @"00")
{label.text = @"Text";}
Run Code Online (Sandbox Code Playgroud)
好的我已经改变了我的代码,但我仍然没有任何建议
label.text = temporaryValue;
if ([label.text floatValue] <= 30)
{label.text = @"text1";}
else if ([label.text floatValue] >= 29)
{label.text = @"text2";}
else if ([label.text floatValue] >= 19)
{label.text = @"text3";}
else if ([label.text floatValue] >= 10)
{label.text = @"text4";}
else if ([label.text floatValue] == 0)
{label.text = @"text5";}
Run Code Online (Sandbox Code Playgroud)
小智 5
你无法比较像这样的字符串的数值; 此操作执行指针比较,即它比较传入的字符串实例的(相当随机的)地址.使用类似下面的内容:
if ([label.text floatValue] >= 30.0) {
}
Run Code Online (Sandbox Code Playgroud)
等等