ViewWillDisappear called twice

My application uses a storyboard with a splitview controller. On the left side, I have a table view with a list of options. On the right side, I have information about the options on the left side. As in the application settings. When the user selects an option on the left side, the contents of the right side change. For each of the options on the left side there is one view manager. These viewcontrollers are built into the navigation controller (one navigation controller for each view manager).

When the user selects an option on the left side, a session is performed. Its type is Replace and its destination is Detailed Separation.

My problem is that every time the user selects an option on the left side, viewWillDisappear from the viewide viewcontroller is called twice. Why is this happening?

+3
source share
3 answers

I also had this, it turned out that my problem was that I was calling the wrong super method, in my case calling [super viewDidAppear:animated]inside the method - (void)viewDidDisappear:(BOOL)animatedin the method that I redefined. Probably not your problem, but just in case someone stumbles on this day.

+6
source

-, , . . , -viewDidDisappear: . , , ( UINavigationController SplitView), , viewDidDisappear.

, . , .

+1

, , .

, "" .

boolean, false (NO).

Then in viewWillDisappear, if the boolean is NO, I set it to YES and show a warning.

I then reset the boolean value NO is viewDidDisappear (this can also be done in an Alert callback).

Not very elegant, but it seems to work quite well.

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

    if ([self isDirty] && ![self showingAlert])
    {
        [self setShowingAlert:YES];

        UIAlertView *alert =
             [[UIAlertView alloc]
                    initWithTitle: @"Save Changes?"
                    message: @"Use it or lose it, matey."
                    delegate: self
                    cancelButtonTitle:@"Save"
                    otherButtonTitles:@"Don't Save",nil];

        [alert show];

        [alert release];
    }
}

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

    [self setShowingAlert:NO];
}
0
source

All Articles