Reputation: 2821
So, after spending the last week carefully designing and planning out my app, a request has come in to change it slightly. In order to make this change, I have to have everything as part of a navigation controller so that I can change views (currently using subviews which won't work correctly).
I have modified my AppDelegate.h and AppDelegate.m to have references to new windows and views , however I just get a black screen on launch.
After using the debugger, I noticed that the window pointer is in AppDelegate is still pointing at memory address 0, after it should have been initialised to the window I connected it to using interface builder.
Clearly I am doing something completely wrong, and I have no idea where to go from here. I don't even know what information I should be providing. To be on the safe side here is my AppDelegate.h:
#import <UIKit/UIKit.h>
#import "InitialisationController.h"
@interface AppDelegate : NSObject <UIApplicationDelegate>
@property (strong, nonatomic) IBOutlet UIWindow *window;
@property (strong, nonatomic) IBOutlet UINavigationController *navigationController;
@property (strong, nonatomic) IBOutlet InitialisationController *initialisationController;
@end
and the didFinishLaunchingWithOptions method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.window addSubview:navigationController.view];
[self setInitialisationController:[[InitialisationController alloc] initWithNibName:@"InitialisationController" bundle:nil]];
//self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
//[self.navigationController pushViewController:initialisationController animated:YES];
[self.navigationController.view addSubview:[[self initialisationController] view]];
return YES;
}
Does anyone have even the slightest idea?
Thanks!
Upvotes: 0
Views: 334
Reputation: 1216
Well you don't really need any of the properties above if your using interface builder except for UIWindow
. Just go into IB and drag the right pointing arrow to the first UINavigationController
in your storyboard.
Now your UIWindow
in AppDelegate will have the navigation controller as its root view.
After that your applicationDidDinishLaunching method ought to be blank.
Not sure how your app is setup but in most of my stuff the UIWindow is initialized by AppDelegate for me so I don't have to do that. It might be wise to create a new project and take a look at the boiler plate code for AppDelegate. Most of the methods there are from the UIApplicationDelegate
protocol and are just there to provide you with information about key events in an application’s execution, not to set it up manually, that's done for you. So those methods are mostly blank.
See: UIApplicationDelegate Protocol Reference http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html
Upvotes: 0
Reputation: 6718
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.initialisationController = [[InitialisationController alloc] initWithNibName:@"InitialisationController" bundle:nil]];
navigationController = [[UINavigationController alloc] initWithRootViewController:self.initialisationController];
[self.window addSubview:[navigationController view]];
[self.window makeKeyAndVisible];
return YES;
}
I think this will helpful to you.
Upvotes: 1
Reputation: 21221
When you initialize your UINavigationController it should be like this
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:[self initialisationController]];
Also remove this line
[self.navigationController.view addSubview:[[self initialisationController] view]];
Upvotes: 0