我正在使用Xcode 4和我的软件在iPhone 4和模拟器上工作良好,但是当我在iPhone 2G或3Gs等设备上测试它时,我立即发生此错误代码:Xcode 4 iphone 3.1.3应用程序不工作
由于未捕获的异常'NSUnknownKeyException'而终止应用,原因:'[setValue:forUndefinedKey:]:该类不是密钥值编码兼容的密钥rootViewController。
寻找解决我建立一个Hello World程序并没有对iPhone 3GS的工作问题的方式......搜索,我发现这个解决方案:
// self.window.rootViewController = self.viewController; [self.window addSubview:[self.viewController view]];
使用addsubview这样,程序应该运行正常......
好了的Hello World运行良好,但我的程序不会在所有的工作......
也许这是我的代码应该改变......(但现在我不真的..)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//this and application should run on 3.1.3
if ([self.window respondsToSelector:@selector(setRootViewController:)])
self.window.rootViewController = self.viewController;
else
[self.window addSubview:self.viewController.view];
// Add registration for remote notifications
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
// Clear application badge when app launches
//application.applicationIconBadgeNumber = 0;
[self.window makeKeyAndVisible];
return YES;
}
我搜索一下这个问题,但我每次搜索,我发现只有改变行 self.window.rootViewController = self.viewController一些信息;
但不幸的是没有多大帮助。
感谢你们为您耐心:)
编辑:
我的代码
if ([self.window respondsToSelector:@selector(setRootViewController:)])
self.window.rootViewController = self.viewController;
else
[self.window addSubview:self.viewController.view];
改变
[self.window addSubview:self.viewController.view];
但错误还是一样。 ..
我用rootViewController评论代码,我使用'[self.window addSubview:self.viewController.view];'但没有改变...同样的错误...也许某处有另一个调用该方法.. – ilmetu
我在整个程序中搜索,但没有其他调用该属性...仍然错误** [ setValue:forUndefinedKey:]:此类不是密钥值编码兼容的关键rootViewController。 ** –
ilmetu