viewWillAppear-related problem

Without giving you all my code examples, I'll made this quick.

Has this ever happened to one of you to get viewWillAppear called only the first time it shows up?

I have this problem with all my view.

For example: When my app starts, I get to the StartView which is a main menu. (viewWillAppear gets called) then I press on one button that'll show a navigation controller (viewWillAppear gets called). Then I get back to the main menu (it does not get called) and then I press on the same navigation controller again and it does not get called.

It would be awesome if someone could points me somewhere, I've been searching for this since two days now...

Also if you need more code samples, I can give you some.

For further reading:

That's how I call my navigation controller:

PremierSoinsAppDelegate *AppDelegate = (PremierSoinsAppDelegate *)[[UIApplication sharedApplication] delegate];

UIView *newView = [AppDelegate.navigationController view];

[newView setFrame:CGRectMake(320.0f, 0.0f, 320.0f, 480.0f)];
[UIView beginAnimations:@"RootViewController" context:nil];
[UIView setAnimationDuration:0.3];
newView setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
UIView commitAnimations];

[AppDelegate.window addSubview:newView];
[AppDelegate.window makeKeyAndVisible];

And that's how I show my menu back:

PremierSoinsAppDelegate *AppDelegate = (PremierSoinsAppDelegate *)[[UIApplication sharedApplication] delegate];

UIView *newView = [AppDelegate.startViewController view];

newView setFrame:CGRectMake(-320.0f, 0.0f, 320.0f, 480.0f)];
UIView beginAnimations:@"StartViewController" context:nil];
UIView setAnimationDuration:0.3];
newView setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[UIView commitAnimations];

[AppDelegate.window addSubview:newView];
[AppDelegate.window makeKeyAndVisible];

Thanks A LOT.


You can implement the UINavigationControllerDelegate in your Nav Controller to propagate the viewWillAppear: messages down. You can implement the message like this:

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    if ([viewController respondsToSelector:@selector(viewDidAppear:)]) {
        [viewController viewDidAppear:animated];

Note that this is the viewDidAppear and not ViewWillAppear version, but they're basically the same.

However, you should note that the fact that you need to do this may be a sign that something else is wrong in your controller/view code and you might want to reask the question giving us more context to answer it. In particular, I'm assuming that somewhere outside of the code you're giving us, you're pushing and popping view controllers as per usual for a Nav Controller.

viewWill/DidAppear: will only be called when using a UINavigationController or UITabBarController (or really any system-provided-viewControlller managing class) to manipulate views. If you're manually doing this (as you seem to do in your second code snippet, these messages won't get sent.

Need Your Help

Same transparency with overlapping patches

matlab plot transparency opacity matlab-figure

I have a geometric figure with a complex shape. However, it can be split into several simpler subfigures. I need to plot them with some transparency, so I use patches. However, in the overlapping a...

Excel pivot table: display rows filtered, but keep total for all rows (unfiltered)

excel pivot-table

I have a pivot table where I filter the data by month. The thing is I need a total column for all months. Is it possible to somehow ignore a select column from being filtered? Or maybe there is a w...