Xcode 尝试构造基于UITabBarController的简单iOS应用程序时出现运行时错误
我的代码可以编译,但当我尝试启动它时,遇到运行时错误 以下是运行时错误:Xcode 尝试构造基于UITabBarController的简单iOS应用程序时出现运行时错误,xcode,ios,uinavigationcontroller,Xcode,Ios,Uinavigationcontroller,我的代码可以编译,但当我尝试启动它时,遇到运行时错误 以下是运行时错误: 2011-04-25 23:56:40.689 Noun[39033:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NounAppDelegate 0x4e1c400> setValue:forUndefinedKey:]: this class is not key value co
2011-04-25 23:56:40.689 Noun[39033:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NounAppDelegate 0x4e1c400> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key viewController.'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc75a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f1b313 objc_exception_throw + 44
2 CoreFoundation 0x00dc74e1 -[NSException raise] + 17
3 Foundation 0x0002f677 _NSSetUsingKeyValueSetter + 135
4 Foundation 0x0002f5e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
5 UIKit 0x004b330c -[UIRuntimeOutletConnection connect] + 112
6 CoreFoundation 0x00d3d8cf -[NSArray makeObjectsPerformSelector:] + 239
7 UIKit 0x004b1d23 -[UINib instantiateWithOwner:options:] + 1041
8 UIKit 0x004b3ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
9 UIKit 0x002b917a -[UIApplication _loadMainNibFile] + 172
10 UIKit 0x002b9cf4 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291
11 UIKit 0x002c4617 -[UIApplication handleEvent:withNewEvent:] + 1533
12 UIKit 0x002bcabf -[UIApplication sendEvent:] + 71
13 UIKit 0x002c1f2e _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x0171f992 PurpleEventCallback + 1550
15 CoreFoundation 0x00da8944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x00d08cf7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x00d05f83 __CFRunLoopRun + 979
18 CoreFoundation 0x00d05840 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00d05761 CFRunLoopRunInMode + 97
20 UIKit 0x002b97d2 -[UIApplication _run] + 623
21 UIKit 0x002c5c93 UIApplicationMain + 1160
22 Noun 0x00001e68 main + 102
23 Noun 0x00001df9 start + 53
)
terminate called after throwing an instance of 'NSException'
我确信这可能是我忘记做的一些琐碎的事情,我正在慢慢地跟上iOS开发的速度“NSUnknownKeyException”当您访问一个不存在的密钥时会出现此异常,这并不总是因为代码,Interface Builder中可能存在一些错误连接。上面的代码是没有问题的,我试过了,我结束了,它运行成功了。尝试检查您的Interface builder连接,可能您缺少一些东西。最有可能的情况是,您首先尝试通过IB添加tabBarController,然后通过代码进行添加。我之前也遇到过同样的问题。问题在于xib文件中存在一个interface builder连接,而应用程序委托中没有相应的IBOutlet条目。 我就是这样修复它的: 在MainWindow.xib文件中查找XML标记“IBObjectContainer”。您很可能会发现这样的条目:
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">viewController</string>
<reference key="source" ref="664661524"/>
<reference key="destination" ref="943309135"/>
</object>
<int key="connectionID">11</int>
</object>
视图控制器
11
您可以安全地删除此条目,因为它似乎是错误地引入到xib文件中的。然后,应用程序代理不再期望IBOutlet条目。
或者,您可以通过名称“viewController”在应用程序代理中添加IBOutlet条目
在进行任何更改之前,请确保备份了xib文件
也许有一种更简单的方法可以从IB中消除这个问题,但我通常不使用IB,这对我来说很有效。感谢saadnib,我正在浏览我的plist文件和NIB。没什么很明显的。
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">viewController</string>
<reference key="source" ref="664661524"/>
<reference key="destination" ref="943309135"/>
</object>
<int key="connectionID">11</int>
</object>