gpt4 book ai didi

objective-c - NSNumber:stringValue 崩溃,描述有效

转载 作者:行者123 更新时间:2023-12-03 17:28:15 31 4
gpt4 key购买 nike

[measureValue stringValue] 给了我这个异常:

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

[measureValue 描述] 完美运行

但我认为我应该在代码中使用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。您正在将 stringValue 发送到 NSString。

关于objective-c - NSNumber:stringValue 崩溃,描述有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7150413/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com