NSNumber:stringValue 崩溃,描述有效
[measureValue stringValue]
给了我这个异常:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSCFString stringValue]:无法识别的选择器发送到实例 0x4dde570”
[measureValue description]
工作正常
但我认为我应该使用 stringValue< /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];
[measureValue stringValue]
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该行返回一个 NSString,而不是 NSNumber。您正在将 stringValue 发送到 NSString。
That line returns an NSString, not an NSNumber. You're sending stringValue to the NSString.