【问题标题】:How can I check if a UILabel's value is more than 0 in an if statement? [closed]如何在 if 语句中检查 UILabel 的值是否大于 0? [关闭]
【发布时间】:2011-12-01 21:22:13
【问题描述】:

如何在 if 语句中检查 UILabel 的值是否大于 0?

我已经尝试了以下代码:

if(ArtCount.text.intValue > 0)
{
}

但它返回以下错误:

2011-12-01 20:52:50.124 iDHSB[2955:707] -[UILabel isEqualToString:]: unrecognized selector sent to instance 0x1a9860
2011-12-01 20:52:50.126 iDHSB[2955:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-    
[UILabel isEqualToString:]: unrecognized selector sent to instance 0x1a9860'
*** First throw call stack:
(0x323e28bf 0x35cfa1e5 0x323e5acb 0x323e4945 0x3233f680 0x3152b191 0x6cff3 0x316cf871 0x323e5814 0x323407e1 0x323403ff      
0x34767e5b 0x323e4ab3 0x3233f680 0x323e5814 0x323407e1 0x33dcb43d 0x33dde8dd 0x323b6b03 0x323b62cf 0x323b5075 0x323384d5 
0x3233839d 0x378b7439 0x315558e1 0x2d0f 0x2758)
terminate called throwing an exception[Switching to process 7171 thread 0x1c03]
(gdb) 

【问题讨论】:

  • 上述代码不太可能是导致上述错误的原因。在调试器中,它实际上在哪里崩溃?你在哪里打电话给isEqualToString:UILabel

标签: iphone objective-c ios xcode uilabel


【解决方案1】:

错误信息:

[UILabel isEqualToString:]: unrecognized selector sent to instance 0x1a9860
2011-12-01 20:52:50.126 iDHSB[2955:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-    
[UILabel isEqualToString:]: unrecognized selector sent to instance

表示导致异常的行在UILabel的实例上调用方法isEqualToString,提供的代码不包含此方法调用。

查找在 UILabel 实例上调用 isEqualToString 的语句。

【讨论】:

    【解决方案2】:
    if ([ArtCount.text intValue] > 0) {
      ...
    }
    

    希望对你有帮助!

    【讨论】:

    • 这与 OP 的代码 100% 相同。当编译器感到困惑时,有时需要避免像这样的点符号,但它不可能导致这个特定的运行时错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    • 1970-01-01
    相关资源
    最近更新 更多