【发布时间】:2012-02-06 05:32:21
【问题描述】:
我有一个一直在做的项目。这是一个仅限 iPhone 的项目,但最近发现我也需要将它提供给 iPad。理论上,我应该能够放入一些 if 语句来在 iPhone/iPad 代码之间切换,但我遇到了一个小问题。在我最初的观点上,我得到了臭名昭著的错误:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x8a2dcf0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key loginButton.'
loginButton 指向一个 UIButton,我的 Login_iPad.xib 中的所有内容都正确链接。
我确定我遗漏了一些小东西,但非常感谢任何帮助。
谢谢!
这是我在 AppDelegate 中的一些代码 - didFinishLaunchingWithOption:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
UIViewController *rootView = [[Login alloc] initWithNibName:@"Login" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:rootView];
} else {
UIViewController *rootView = [[Login alloc] initWithNibName:@"Login_iPad" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:rootView];
}
更新:如果我删除所有的出口(包括视图出口),我当然会得到这个错误:
loaded the "Login_iPad" nib but the view outlet was not set
但是,如果我只添加视图的出口,我会得到:
this class is not key value coding-compliant for the key view
对我来说没有意义。我将 XIB 的类设置为与 iPhone XIB 相同的类。但是,我知道我忽略了一些东西。
作为 iPad 应用程序运行时,我似乎无法链接任何内容。甚至视图都没有……否则它会抛出该错误。
【问题讨论】:
-
听起来你的 iPad 笔尖上的插座连接不正确...
-
你的xib有问题,如果有任何警告,你检查所有属性了吗?
标签: iphone xcode cocoa-touch ipad uibutton