“由于未捕获的异常而终止应用程序" ..找不到主窗口,该窗口不再存在 [英] 'Terminating app due to uncaught exception'.. it couldn't find MainWindow, which no longer exists
问题描述
我不久前删除了所有.xib文件,最近又更改了标识符.现在它开始给我这个错误:
I deleted all my .xib files a while ago, and recently changed my identifier. Now its started giving me this error:
由于未捕获而终止应用程序例外'NSInternalInconsistencyException',原因:无法在捆绑包中加载NIB:'NSBundle(已加载)',名称为'MainWindow'
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'MainWindow''
MainWindow不久前已被删除,并且从部署信息中删除MainWindow意味着我只得到了黑屏.这是我在我的应用程序委托中拥有的代码:
MainWindow was deleted a while ago, and removing MainWindow from deployment info means that I'm just given a black screen. This is the code i have in my app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
我想念什么吗?我想我应该删除MainWindow,但是正如我所说,这只是给我一个黑屏.
Am i missing something? I presume i should remove MainWindow but as i say, this is just giving me a black screen.
推荐答案
由于在 Info.plist
中设置了 NSMainNibFile
值,因此出现此错误.它告诉操作系统在启动时打开该 NIB
文件.由于出于某种原因而放弃了 NIB
,因此您将不得不通过删除 NIB
文件来填补创建的漏洞.
You are getting this error because the NSMainNibFile
value is set in your Info.plist
. It tells the OS to open that NIB
file at launch. Since you're doing away with NIB
s for some reason, you will have to fill in the holes that you've created by deleting the NIB
file.
- 您必须从
Info.plist
中删除密钥. -
您必须在
main.m
中进行一些更改.通常,MainWindow.xib
包含有关您的应用程序委托的信息,但是现在您需要提供它.找到读取int retVal = UIApplicationMain(argc,argv,nil,nil);
的行,并将其替换为int retVal = UIApplicationMain(argc,argv,nil,@"yourDelegateClassName");
- You've to delete the key from the
Info.plist
. You have to make some changes in your
main.m
. Usually theMainWindow.xib
contained the information about your application delegate but now you need to provide it. Find the line that readsint retVal = UIApplicationMain(argc, argv, nil, nil);
and replace it withint retVal = UIApplicationMain(argc, argv, nil, @"yourDelegateClassName");
到目前为止,您已完成的操作将实例化应用程序委托,并且您的 application:didFinishLaunchingWithOptions:
将被调用,但您的 window
尚未设置为 NIB
文件再次解决了该问题.这将适用于您所有的网点.不仅是您的窗口".
What you've done so far will instantiate the application delegate and your application:didFinishLaunchingWithOptions:
will get called but your window
isn't set yet as it was taken care of by the NIB
file again. This will apply to all your outlets. Not only your `window.
您必须像这样在 application:didFinishLaunchingWithOptions:
方法中添加一些内容,
You will have to make some additions to your application:didFinishLaunchingWithOptions:
method like this,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Instantiate Window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Instantiate Root view controller
RootViewController * viewController = [[[RootViewController alloc] init] autorelease];
// Instantiate navigation controller
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
以上方法只是一个模板,必须根据您的要求进行修改.
The above method is just a template and must be modified to your requirement.
这篇关于“由于未捕获的异常而终止应用程序" ..找不到主窗口,该窗口不再存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!