开发者

Building a Navigation-Based project starting from a Window based project

开发者 https://www.devze.com 2023-04-05 19:47 出处:网络
Just trying to wrap my head around how different project types are built and I must be missing something.

Just trying to wrap my head around how different project types are built and I must be missing something.

I'm trying to start with a开发者_运维技巧 window based application and just add a Navigation Controller so I understand how the different components work with the Window and App delegate.

Here's what I did:

  • Created a Window based project
  • In my app delegate.h I added

    @property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

In my app delegate.m I added:

@synthesize navigationController;

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}
  • In the MainWindow.xib file I added a NavigationController below the Window
  • Created a new UIViewController subclass (FirstView.h/m)
  • Pointed the NavigationController's root view controller to FirstView

Builds clean, when I launch I get an all white screen.

What am I missing?


Add this [self.window addSubview:self.navigationController.view]; You need to add the navigation controllers view to the window. Also make sure that the outlet for the navigation controller is connected. You will also need to add root view controller for the navigation controller


Actually barfoon..your navigation controller does not contains any UIViewController. First of all create new UIViewController and than add it to UINavigationController. UINavigationController is just like stack ,which handle each and every added UIViewController i.e traversing like back and forth. Ex..

ToDoController *toDoObj = [[ToDoController alloc] initWithNibName:@"ToDoController" bundle:[NSBundle mainBundle]];
UINavigationController *toDoNav = [[UINavigationController alloc] initWithRootViewController:toDoObj];
[self.window addSubview:toDoNav.view];


Figured it out - I had to create a new Referencing outlet and connect the Navigation Controller to the App Delegate in the .xib.

0

精彩评论

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

关注公众号