UINavigationController ViewDidDisappear not firing for view
I'm using MonoTouch. When I push a new controller onto the stack of a UINavigationController, it works fine. When I hit the back button, NO events fire, even though visually, the view is popped off the stack. Specifically, I want to use ViewDidDisappear and ViewDidAppear to do some stuff:
SurveyEditor editor = new SurveyEditor(surveyInstance);
NavigationController.PushViewController(editor, true);
then in SurveyEditor:
public override void ViewWillDisappear (bool animated)
{
Console.WriteLine("SurveyEditor ViewWillDisappear");
base.ViewWillDisappear (animated);
}
public override void ViewDidDisappear (bool animated)
{
Console.WriteLine(开发者_JAVA百科"SurveyEditor ViewDidDisappear");
base.ViewDidDisappear (animated);
}
None of these are being called, and in my root view, ViewDidAppear is also not getting called! Starting to lose my mind on this one.
It turns out that if I have a navigation controller inside a ViewController, these events do not fire.
If you launch the nav controller from the view Controller using the following, it does get called:
[self presentModalViewController:navigationController animated:YES];
(sorry this is not MonoTouch - I encountered the problem in the regular Objective-C. This was my solution.)
Look at Dustin Clark's comment here.
Call it yourself, if it's not getting called. There's nothing magic happening about it, it's just a method on that ViewController. Let it know it's about to disappear.
精彩评论