gpt4 book ai didi

xcode - 尝试构建基于简单 UITabBarController 的 iOS 应用程序时出现运行时错误

转载 作者:行者123 更新时间:2023-11-29 05:04:57 24 4
gpt4 key购买 nike

我的代码可以编译,但当我尝试启动它时遇到运行时错误。

这是运行时错误:

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'

这是我的代码(相关方法)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//Initiate TabBarController
self.tabBarController = [[UITabBarController alloc] init];

NSMutableArray *viewControllersForTabController = [[NSMutableArray alloc] initWithCapacity:2];

NounViewController *firstViewController = [[NounViewController alloc] initWithNibName:@"NounViewController" bundle:[NSBundle mainBundle]];
[viewControllersForTabController addObject:firstViewController];
[firstViewController release];

PostLoginViewController *secondViewController = [[PostLoginViewController alloc] initWithNibName:@"PostLoginViewController" bundle:[NSBundle mainBundle]];
[viewControllersForTabController addObject:secondViewController];
[secondViewController release];

[tabBarController setViewControllers:viewControllersForTabController];
[viewControllersForTabController release];

[window addSubview:tabBarController.view];

return YES;
}

我确信这可能是我忘记做的一些微不足道的事情,我正在慢慢跟上 iOS 开发的速度

最佳答案

“NSUnknownKeyException”当您访问不存在的 key 时会出现此异常,这并不总是因为代码,Interface Builder 中可能存在一些错误连接。上面的代码没有问题,我试了一下,运行成功。尝试检查您的界面生成器连接,可能您缺少一些东西。最有可能的是,您首先尝试通过 IB 添加 tabBarController,然后通过代码执行此操作。

关于xcode - 尝试构建基于简单 UITabBarController 的 iOS 应用程序时出现运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5785748/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com