[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];

最佳答案

 NSNumber *measureValue = [NSString stringWithFormat:@"%i", [cellContent integerValue]];

该行返回一个NSString,而不是NSNumber。您正在将字符串Value发送到NSString。

10-06 01:10