开发者

NSNumber: stringValue crashes, description works

[measureValue stringVal开发者_运维知识库ue] gives me this exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString stringValue]: unrecognized selector sent to instance 0x4dde570'

[measureValue description] works perfectly

But I think I should use stringValue in the code, right?

This is the code:

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

That line returns an NSString, not an NSNumber. You're sending stringValue to the NSString.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜