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 NIB
s for some reason, you will have to fill in the holes that you've created by deleting the NIB
file.
- 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");
What you've done so far will instantiate the application delegate and your
application:didFinishLaunchingWithOptions:
will get called but yourwindow
isn't set yet as it was taken care of by theNIB
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.
精彩评论