开发者

'Terminating app due to uncaught exception'.. it couldn't find MainWindow, which no longer exists

开发者 https://www.devze.com 2023-03-13 21:11 出处:网络
I deleted all my .xib files a while ago, and recently changed my identifier. Now its started giving me this error:

I deleted all my .xib files a while ago, and recently changed my identifier. Now its started giving me this error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name '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 {    

    [applic开发者_Python百科ation setStatusBarStyle:UIStatusBarStyleBlackOpaque];
    [window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

Am i missing something? I presume i should remove MainWindow but as i say, this is just giving me a black screen.


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 NIBs for some reason, you will have to fill in the holes that you've created by deleting the NIB file.

  1. You've to delete the key from the Info.plist.
  2. You have to make some changes in your main.m. Usually the MainWindow.xib contained the information about your application delegate but now you need to provide it. Find the line that reads int retVal = UIApplicationMain(argc, argv, nil, nil); and replace it with int retVal = UIApplicationMain(argc, argv, nil, @"yourDelegateClassName");

  3. 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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消