iphone - label.text 和 NSNumber 错误

标签 iphone objective-c ios

我想这样做:
我有这样的字典:

[myMutableDictionary setValue:myNSNumber forKey:@"myKey"];

myNSNumber 是一个 NSNumber。

myCell.label.text = [self.myMutableDictionary objectForkey@"myKey"];

当我将存储在字典中的数字分配给 myCell 中的标签时出现错误。 错误是:

je suis la 2011-05-02 15:01:01.264 [] -[NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x225d00 2011-05-02 15:01:01.319 [] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x225d00'

最佳答案

NSNumber不是 NSString 并且标签的文本需要设置为 NSString

NSNumber *num = (NSNumber*)[self.myMutableDictionnary objectForkey@"myKey"];
myCell.label.text = [num stringValue];

关于iphone - label.text 和 NSNumber 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5857446/

相关文章:

android - Cordova:与 native 插件共享 webview cookie

ios - iOS按修改日期导入联系人

iphone - 在 iPhone 上记录 objc_msgSend()

iphone - 如何在更改 UIImageView 时制作动画

ios - 正则表达式卡在 iPhone 中用于电子邮件验证

ios - UIImageView.animationImages 显示旋转图像

iphone - 处理UIScrollView中UITextField的touchesBegan方法

ios - Swift:线程 1:EXC_BAD_ACCESS 即使有 guard

ios - Objective-C 桥接问题。如何在 Swift 项目中使用 Obj-C 框架?

objective-c - 将类 y 中类 x 的编程实例链接到类 x 的 View Controller