2

My iPad app uses the standard UISplitViewController. My problem is, if I

  • Rotate to portrait, I put a Popover button for the Master list - Fine
  • Select an item via the popover, that changes the detailview (This uses a prepareForSegue which sets self.splitViewController.delegate = newViewDetailViewController;
  • The resulting detailview is now missing a popoverbutton. If I rotate to landscape, the master list appears. If I then again rotate to portrait, a popoverbutton appears.

So - How can I ensure willHideViewController will be called on viewDidLoad, for example? I can detect what the orientation is, but I still need the barbuttonitem and popovercontroller needed in

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController

For now I am following Apples MultipleDetailView example as suggested here.

But since I am having multiple MasterControllers as well, it's a real hassle to store (a static) pointer to the popoverbutton item and setting it every time I push a level on my masterview controller.

Hopefully, someone has a good way of solving this problem :-)

Community
  • 1
  • 1
CracyD
  • 368
  • 4
  • 16
  • I'm having this same issue, did you ever get it figured out? – Bek Dec 19 '11 at 11:46
  • I ended using the example I linked to from Apple. It wasn't an issue with multiple mastercontrollers, since I realized that the popoverbutton gets delivered to me in the `willHideViewController` method. So, I have a `SubstitutableDetailViewController` protocol that my detail views implement. – CracyD Jan 02 '12 at 09:08
  • I'm having the same problem, and I'm using the same Apple sample code that uses the `SubstitutableDetailViewController` protocol. It doesn't receive `(void)splitViewController:(UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem` when the view controller was loaded before and rotated when it was not visible. – avance Oct 16 '12 at 19:50

1 Answers1

3

I ran into the same problem and finally figured out what was missing. There is a little code in the AppDelegate to performs some initialization. It is in the didFinishLaunchingWithOptions method. Here is the code that goes in there:

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;

They're all important to operate the split view controller, but the last line is the most line for getting the method to fire is the last one. I am building a universal application and this was missing. To ensure that it didn't affect my iPhone side I wrapped it in a UI_USER_INTERFACE_IDIOM check.

Rob
  • 4,149
  • 5
  • 34
  • 48
  • 1
    wrapping it in the UI user interface idiom check matches what happens in the generated AppDelegate.m code when a master-detail app is generated via template in Xcode. if you don't do this, the attempt to send a message to @selector viewControllers would crash your app. – john.k.doe Apr 24 '12 at 08:04