我想这样做:
我有这样的字典:
[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/