1

代码很简单:

static NSNumberFormatter *numberFormatter = nil;

if (numberFormatter == nil) {
    numberFormatter = [[NSDateFormatter alloc] init];
    [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
}

但是,它在最后一行崩溃:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDateFormatter setNumberStyle:]: unrecognized selector sent to instance 0x5c378d0'

这怎么可能?

4

1 回答 1

4

因为您创建的是 NSDateFormatter,而不是 NSNumberFormatter。

于 2011-07-25T00:45:52.977 回答