我对此很陌生,并且试图制作一个简单的温度转换应用程序。下面是有没有被抛出错误:iOS应用程序在测试启动时抛出错误
2014-02-28 20:35:46.954 Temperature Converter[5899:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TemperatureConverterViewController 0x8a939a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key convertTemperatureButton.'
*** First throw call stack:
(
0 CoreFoundation 0x017395e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bc8b6 objc_exception_throw + 44
2 CoreFoundation 0x017c96a1 -[NSException raise] + 17
3 Foundation 0x0117d9ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x010e9cfb _NSSetUsingKeyValueSetter + 88
5 Foundation 0x010e9253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x0114b70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7 UIKit 0x004cca15 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x014ce7d2 -[NSObject performSelector:] + 62
9 CoreFoundation 0x01734b6a -[NSArray makeObjectsPerformSelector:] + 314
10 UIKit 0x004cb56e -[UINib instantiateWithOwner:options:] + 1417
11 UIKit 0x0033d605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
12 UIKit 0x0033ddad -[UIViewController loadView] + 302
13 UIKit 0x0033e0ae -[UIViewController loadViewIfRequired] + 78
14 UIKit 0x0033e5b4 -[UIViewController view] + 35
15 UIKit 0x002669fd -[UIWindow addRootViewControllerViewIfPossible] + 66
16 UIKit 0x00266d97 -[UIWindow _setHidden:forced:] + 312
17 UIKit 0x0026702d -[UIWindow _orderFrontWithoutMakingKey] + 49
18 UIKit 0x0027189a -[UIWindow makeKeyAndVisible] + 65
19 UIKit 0x00224cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
20 UIKit 0x002293a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
21 UIKit 0x0023d87c -[UIApplication handleEvent:withNewEvent:] + 3447
22 UIKit 0x0023dde9 -[UIApplication sendEvent:] + 85
23 UIKit 0x0022b025 _UIApplicationHandleEvent + 736
24 GraphicsServices 0x036e02f6 _PurpleEventCallback + 776
25 GraphicsServices 0x036dfe01 PurpleEventCallback + 46
26 CoreFoundation 0x016b4d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
27 CoreFoundation 0x016b4a9b __CFRunLoopDoSource1 + 523
28 CoreFoundation 0x016df77c __CFRunLoopRun + 2156
29 CoreFoundation 0x016deac3 CFRunLoopRunSpecific + 467
30 CoreFoundation 0x016de8db CFRunLoopRunInMode + 123
31 UIKit 0x00228add -[UIApplication _run] + 840
32 UIKit 0x0022ad3b UIApplicationMain + 1225
33 Temperature Converter 0x00002eed main + 141
34 libdyld.dylib 0x01d7770d start + 1
35 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
现在,据我所知,有一些错误的,我按钮的功能所以这里是我的接口和实现:
#import <UIKit/UIKit.h>
@interface TemperatureConverterViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *temperatureField;
@property (weak, nonatomic) IBOutlet UILabel *conversionResult;
- (IBAction)convertToFahrenheit:(id)sender;
@end
继承人的实现(.M文件)
#import "TemperatureConverterViewController.h"
@interface TemperatureConverterViewController()
@end
@implementation TemperatureConverterViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)convertToFahrenheit:(id)sender {
double celsius = [_temperatureField.text doubleValue];
double fahrenheit = (celsius+32)*1.8;
NSString *result = [[NSString alloc] initWithFormat: @"Fahrenheit: %f",fahrenheit];
_conversionResult.text = result;
}
@end
任何人都可以找到问题吗?我不能:(
谢谢。
UPDATE!
当我按我的文本字段中的虚拟设备,键盘的表演,但它并没有消失的时候我按下按钮!任何人都知道我是如何解决这一问题?
太谢谢你了!
检查您的XIB或故事板的连接,并确保一切都正确挂接。有可能你可能已经连接了一个IBOutlet,你之后从你的界面中删除了这个IBOutlet,这个IBOutlet仍然在文件所有者连接中出现。 – Aaron
设置异常断点。当它被击中时会连续几次,并且会有错误信息。 – zaph
ConvertTemperature按钮没有连接 - 可能是一个IBOutlet – GuybrushThreepwood