Question

The premise is remarkably simple: I want to display a modal view in an iPad app that uses a UISplitViewController.

The view hierarchy is straight-forward:

                                              /- TableViewController1
                     /- root:TabBarController -- TableViewController2
SplitViewController -
                     \- detail:CustomViewController

When I click on one of the table cells in TableViewController1, I open a modal view:

- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)ip {
  UIViewController *vc = [[MyModalClass alloc] init];
  UINavigationController *nc = [[UINavigationController alloc]
                                initWithRootViewController:vc];
  nc.modalPresentationStyle = UIModalPresentationFormSheet;
  nc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  [self presentModalViewController:nc animated:true];
  [nc release];
  [vc release];
}

This works just fine: the view appears. The problems start when I try to dismiss it in any orientation other than landscape.

In ModalViewController, the following method is triggered by a UITabBarButton in the navigation bar:

- (void) closeButtonInNavBarWasClicked:(id)sender {
  [self dismissModalViewControllerAnimated:true];
}

And THIS is where the problems start.

When this code is called, the modal view disappears, BUT: the TabBarController (the split view's root view) is suddenly rotated and resized. The content is suddenly sideways, and partially covers the details view. The details view isn't resized to be smaller, it's just partially covered by the root view.

The only situation where this problem doesn't appear is when I tap on the TableViewController1 cell when the app is in portrait mode. Despite the root view being in a popover (which could be an ample source of bugs), everything works fine.

Some things I have already tried, with no success:

  • Dump the tab bar, just display TableViewController1 as the root controller of the split view
  • Create a delegate protocol so that the parent TableViewController1 dismisses the modal view rather than the MyModalClass view itself.
  • Presenting/dismissing the modal view on TableViewController1.splitViewController actually makes things worse: the view doesn't even appear.
  • Sacrificing several goats also did not help.

I would hugely appreciate any input on this issue.

Was it helpful?

Solution

I have a sort-of-answer to my own question: I used Instruments to systematically eliminate all memory leaks in my app. Once I had done that, the problem vanished.

OTHER TIPS

I had the same problem as you, I solved it by programatically temporarily force rotate my presenting viewController (once returned to it), in its viewDidAppear method to some arbitrary rotation. Of course without animation. And then rotated it back to the wanted orientation (which I saved in prior to the rotation).

So if vc1 displays vc2 modally, and the user rotates vc2 I set the orientation of vc1 according to current orientation of vc2 by calling: UIInterfaceOrientation currentOrientation = self.interfaceOrientation; //store current orientation of vc2 (modal view) [vc1 willRotateToInterfaceOrientation:currentOrientation duration:0];

Then I dissmiss vc2 and in viewWillAppear of vc1 I do this:

-(void) viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

/* Store wanted orientation */
UIInterfaceOrientation currentOrientation = self.interfaceOrientation; 

/* rotate to some arbitrary orientation, this solves the bug. */
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortraitUpsideDown animated:NO]; 

[[UIDevice currentDevice] setOrientation:currentOrientation animated:NO]; //restore wanted orientation.

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top