Search code examples
macoscocoansviewcontroller

viewDidLoad not firing


All,
I'm creating a windowController from my applicationDidFinishLaunching method...

(void)applicationDidFinishLaunching:(NSNotification *)aNotification {
   myWC = [[myWindowController alloc] initWithWindowNibName:@"myWindowControllerName"];

   [myWC showWindow:self];
}

At this point, the method windowDidLoad is called. From there, I call the method to load the viewController...

(void)windowDidLoad {
    [super windowDidLoad];

    homeScreenVC = [[HomeScreen alloc] initWithNibName:@"HomeScreen" bundle:nil];

    [baseView addSubview:[homeScreenVC view]];
}

While the view appears, the method viewDidLoad is not called. I tried viewDidAppear and that was not called either. I also tried loading the viewController immediately after loading the window and that also did not work. Any ideas?

Any help would be appreciated. Thank you.


Solution

  • For OSX You should use loadView


    EDIT: You can load your show homeScreenVC from appDelegate:

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
        homeScreenVC = [[HomeScreen alloc] initWithNibName:@"HomeScreen" bundle:nil];
        [self.window.contentView addSubview:self.homeViewController.view];
        homeScreenVC.view.frame = ((NSView*)self.window.contentView).bounds;
    }
    

    Don't load the view here, this method gets called when the view is loaded

    -(void)loadView{
        [super loadView];
        //anything you want to do when home screen is presented
    }