Alex Rivera | Logout

viewWillAppear, viewDidAppear not being called, not firing

Asked 2010-08-24T20:16:18.950
39

(This is both question and answer since it took quite a bit of digging to find the real answer.)

Symptom: viewWillAppear, viewDidAppear were not being called in my UIViewController.

Cause: Embedding a UINavigationController or UITabBarController (my case) in a UIViewController somehow interrupts with the calling of these methods.

Solution: Call them manually in the UIViewController that contains the aforementioned UINavigationController / UITabBarController.

For example (assuming projectNavigationController is your UINavigationController):

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [projectNavigationController viewWillAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated];
    [projectNavigationController viewWillDisappear:animated];
}

-(void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated];
    [projectNavigationController viewDidAppear:animated];
}

-(void)viewDidDisappear:(BOOL)animated { 
    [super viewDidDisappear:animated];
    [projectNavigationController viewDidDisappear:animated];
}

In my case I had an inner UITabBarController and I called the methods accordingly and all was solved.

(Attribution on the solution: http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/)

Edit
Report

1 Answer

0

I just saw this same circumstance. Earlier the interface builder segue triggered by a table cell selection had stopped working and after some exasperation digging into the code, I just set it up manually, calling from the cell-selection override in the table view delegate.

Later I made some layout changes in the called view controller and saw that viewDidAppear wasn't being called, as described above. The debug output made reference to "nested push operations" or something, and since I had a big comment to myself in my manual push operation

#warning I SHOULD NOT HAVE TO DO THIS!!

I breakpointed the segue code and, sure enough, the IB segue was now working, and it was my manual operation in the table cell selection code that was messing up the delegate calls in the called view. I removed the manual code and everything is fine again.

It does seem odd that the cell select code gets called after the view is pushed. I have to do a protocol and delegate to get the indexpath of the selected cell in the caller.

answered 2012-01-15T09:43:28.223

Your Answer