[measureValue stringValue]
给了我这个例外:
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [NSCFString stringValue]:无法识别的选择器发送到实例0x4dde570'
[measureValue description]
完美无缺
但我认为我应该在代码中使用stringValue
,对吗?
这是代码:
NSNumber *measureValue = [NSString stringWithFormat:@"%i", [cellContent integerValue]];
//if imperial (inches)
if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"Measure"] isEqualToString:@"Imperial"] ) {
//if height
if ([currentQuestion isEqualToString:@"Height"]) {
measureValue = [NSNumber numberWithDouble:(2.54 * [measureValue doubleValue])];
//elseif weight
} else {
measureValue = [NSNumber numberWithDouble:(0.45359237 * [measureValue doubleValue])];
}
//NSLog(@"%@", [measureValue stringValue]);
cellContent = [measureValue description];
答案 0 :(得分:10)
NSNumber *measureValue = [NSString stringWithFormat:@"%i", [cellContent integerValue]];
该行返回NSString,而不是NSNumber。您正在将stringValue发送到NSString。