我在 NSSTRING 中有一个简单的值,我想将其转换为 NSNumber。我一直在我的代码中这样做,由于某种原因,这次它不起作用。你觉得这有什么问题吗?
NSNumberFormatter * num_formatter = [[NSNumberFormatter alloc] init];
[num_formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *score;
NSString *mystr = [[player ScoresArray] objectAtIndex:currentKeeper - 1];
NSLog(@"here is my string: -%@-", mystr);
score = [num_formatter numberFromString:mystr]; // crash occurs on this line. see error below...
NSLog(@"now it is: %d", [score intValue]); // it never gets to this line...
以下是上述代码的输出:
这是我的字符串:-3-
这是我得到的错误:
2013-02-26 17:21:48.912 Golf Whiz[50407:c07] -[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xcb5fa90
2013-02-26 17:21:48.912 Golf Whiz[50407:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xcb5fa90'
*** First throw call stack: