tags:

views:

202

answers:

3

When pushing a viewcontroller using UINavigationController into the view:

  1. What is necessary for it to trigger viewDidAppear: and viewWillAppear: ?
  2. What makes it fail to not trigger viewDidAppear: and viewWillAppear: ?

We are having a hard time relying on wether those methods gets triggered or not.

A: 

Both methods should be called when you are about to display a view....right before it shows viewWillAppear is called, right after it shows viewDidAppear is called...anyway you can always refer to the documentation of UIViewController here Uiviewcontroller ref

Daniel
allright. but what can cause it to not call those methods?
Fossli
the view isnt being displayed properly?
Daniel
+1  A: 

UINavigationController calls these methods directly on the controller that's being pushed when you call pushViewController:animated: Similarly, UITabBarController calls these methods directly when you switch tabs, and UIViewController calls them when you use presentModalViewController:animated:. They also get called when a view controller's view is added to a window. I've never seen these methods fail to get called in these specific contexts.

Now bear in mind that these methods only get called on the controller being pushed or presented in these specific contexts. These methods won't get called, for example, if you add your view controller's view as a subview of some view other than the UIWindow. Apple's documentation states that view controllers are intended only to be used with full screen views, which are typically presented using one of the methods described above. It's possible to ignore Apple's advice associate a view controller with a subview of another view controller, but you'll have to delegate the viewWill/DidAppear/Disappear calls from the container view controller to the nested controller manually.

cduhn
I have 3 tabs in my tabbar controller. Each having a UITableView as its self.view. Each view controller is loaded with initWithNibName. I found viewDidAppear is not called at all. Even when you tap on the the tabbar items. Even if I switch views clicking on the table cells. But when I load a modal view controller in one of the view, after that viewdidappear is behaving as we expect. Seems the first tabbar view controllers have to unloaded once then it starts working. I cannot find any other workaround.
karim
A: 

Check that you've got the function name exactly right, for example:

- (void)viewWillAppear:(BOOL)animated

For example, if you forget to declare the animated parameter, your function won't get called.

This may sound obvious, but I've made this mistake and since the original post doesn't have a code sample I thought I'd share!

Matt