アプリを使用しているときにこのエラーが発生します。これは単純な電卓で、数字を押すと発生します。
2013-01-12 21:13:32.175 Basic Calc[1683:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '***
-objCType only defined for abstract class. Define -[FormatNumber objCType]!'
*** First throw call stack: (0x1c8f012 0x10cce7e 0x1c8edeb 0xb96f35 0xba6b3f 0xb1a049 0xac8fc5 0x1c09ac6 0x1c4f13c 0xac8f60 0xac8eab 0x2b4b 0x10e0705 0x17920 0x178b8 0xd8671 0xd8bcf 0xd7872 0x4716d 0x47552 0x253aa 0x16cf8 0x1beadf9 0x1beaad0 0x1c04bf5 0x1c04962 0x1c35bb6 0x1c34f44 0x1c34e1b 0x1be97e3 0x1be9668 0x1465c 0x27cd 0x26f5) libc++abi.dylib: terminate called throwing an exception
これが私のコードの一部です:
MainViewController.m
currentNumber = currentNumber *10 + (float)[sender tag];
FormatNumber *convertedNumber;
convertedNumber = [[FormatNumber alloc] init];
[convertedNumber getNumber:currentNumber];
calculatorScreen.text = [NSString stringWithFormat:@"%@",convertedNumber];
FormatNumber.m
@interface FormatNumber: NSNumber
{
NSString *nf;
}
-(NSString *) getNumber:(float)n1;
@end
FormatNumber.m
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:2];
[formatter setMinimumFractionDigits:0];
nf = [formatter stringFromNumber:[NSNumber numberWithFloat: n1]];
return nf;
また、エラーが発生した場合、コードはmain.mのこの行を指しています。
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
何か案は?
新しいコード:
MainViewController.h
currentNumber = currentNumber *10 + (float)[sender tag];
NSNumber *convertedNumber = [[NSNumber alloc] init];
NSString *finalValue = [convertedNumber customFormatNumber:currentNumber];
calculatorScreen.text = [NSString stringWithFormat:@"%@",finalValue];
NSNumber + FormatNumber.h
@interface NSNumber (FormatNumber)
-(NSString *) customFormatNumber:(float)n1;
@end
NSNumber + FormatNumber.m
@implementation NSNumber(FormatNumber)
-(NSString *) customFormatNumber:(float)n1
{
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:2];
[formatter setMinimumFractionDigits:0];
NSString *nf = [formatter stringFromNumber:[NSNumber numberWithFloat:n1]];
return nf;