转载自:http://stackoverflow.com/questions/6625493/pop-and-push-the-same-view-does-not-invoke-the-viewwillappear-method


Pop and push the same view does not invoke the viewWillAppear() method

When I receive a local notification i do the following:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notif {
    [navController popToRootViewControllerAnimated:NO];
    [navController pushViewController:notificationSplashViewController animated:YES];
}

If my notificationSplashViewController is the current ViewController, its viewWillAppear()method is not invoked. How can I detect the re-push of notificationSplashViewController?

link|improve this question

0% accept rate
 
wild guess - what happens if you animate the pop? – Rayfleck Jul 8 '11 at 23:47
 
... a disaster! The navigation bar gets crazy, overlapping all the titles of the pushed viewcontrollers. Actually, on the console I get: nested push animation can result in corrupted navigation bar Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted. – Ivan Leonardi Jul 9 '11 at 12:59
 
Gaak! That is bad. Don't do that :-) Another wild guess - move the push into it's own method (called thePushMethod), and after the pop, invoke that method like this: [self performSelector:@selector(thePushMethod) withObject:nil afterDelay:0.0]; – Rayfleck Jul 9 '11 at 14:55
 
Fine! It works! :) Thank you! Could you explain me why this workaround works? – Ivan Leonardi Jul 11 '11 at 11:35
 
When you invoke a selector like that, it does not do it in real time, it puts it on queue to be performed during the next run-loop, and that gives it enough time for the first animation to finish. – Rayfleck Jul 11 '11 at 12:13

......   

[self performSelector:@selector(thePushMethod) withObject:nil afterDelay:0.5];

    }

    [self hideDial];

}

- (void)thePushMethod

{

    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];

}