Reputation: 1133
My app uses storyboard with a splitviewcontroller. On the left side I have tableview with a list of options. On the right side I have some information for the options on the left side. Just as in the settings app. When the user choose an option on the left side the content of the right side changes. There are one viewcontroller for every one of the options on the left side. These viewcontrollers are embedded inside a navigationviewcontroller (one navigationviewcontroller for every viewcontroller).
When the user select an option on the left side a segue is performed. Its type is "Replace" and its destination "Detail Split".
My problem is that every time the user select an option on the left side, viewWillDisappear of the rightside viewcontroller is called twice. Why is it happening?
Upvotes: 3
Views: 3148
Reputation: 14484
I had this as well, turned out my problem was that I was calling the wrong super method, in my case calling [super viewDidAppear:animated]
inside the - (void)viewDidDisappear:(BOOL)animated
method in the method I was overriding. Probably not your issue, but just in case someone stumbles on this one day.
Upvotes: 7
Reputation: 21870
First, let me say, this sucks. I ran into this problem as well and found your post. After experimentation, we realized that -viewDidDisappear:
only gets called once. So, whatever bug is causing the double call (when the view controller is inside a UINavigationController in the SplitView) doesn't seem to happen on the viewDidDisappear.
It's a stupid kludge, but the bug is stupid too. Hope this helps.
Upvotes: 1
Reputation: 6763
OK, I spent a while investigating this, but in the end I've had to go with a workaround.
In my situation, I want to show an alert if 'leaving' a detail view without saving the detail view content.
I added an instance variable boolean, initially set to false (NO).
Then, in viewWillDisappear, if the boolean is NO, I set it to YES, and show the alert.
I then reset the boolean to NO is viewDidDisappear (this could also be done in the Alert callback).
Not terribly elegant, but this seems to work well enough.
- (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];
}
Upvotes: 0