1
votes

I have the following problem: When I'm trying to replace the detailView of my UISplitViewController by selecting a item in a table within my masterView, the navigationbarbutton for the masterView disappears. If the iPad is in landscapemode the replacement works without any sign of an error. The button comes back when I rotate the iPad first to landscapemode and then back to portraitmode. So I guess that I've set the delegate for the uisplitviewcontroller correct. Is there any possibility to tell the uisplitviewcontroller to ask the delegate to update the button without rotating the device or did I forget something at the time when I replaced the detailView - here is the code for the replacement within the masterViewController

MyViewController *myvc = [[MyViewController alloc] initWithNibName:nil bundle:nil];
[self.subservientController setViewControllers:[NSArray arrayWithObject:myvc] animated:NO];
self.splitViewController.delegate = myvc;

The masters subservientController is a reference of the navigationcontroller in which the detailViewController (MyViewController) will be pushed

1

1 Answers

1
votes

This is a very old question and there have been many other questions about the same types of things so I was surprised to see this one unanswered. Not sure that you still need an answer, but for anyone else that finds this in a search, I'm hoping this helps.

The thing that confused me here is that when you say the "navigationbarbutton for the masterView disappears", it really only seems like that. What's really going on is that it never even existed yet in your brand new view that you just replaced the old view with. You even mention this in the question, that you replaced the detail view. This made my head spin when I looked at the files generated from the Master-Detail Application Template I originally created my app from, which assigned the UISplitViewConrollerDelegate to the detail view.

So when you or I replace the detail view with a new view, we also just wiped out the UISplitViewConrollerDelegate so I had to make sure the new detail view also acts as a UISplitViewConrollerDelegate, which created other issues for keeping track of the popoverButtonItem that was being kept in an iVar.

In the UISplitViewController Class Reference it says:

There are two main approaches you can take, depending on the type of application you create:

A simple master-detail interface in which the detail view remains constant. In this configuration, a single view controller manages the detail view for the lifetime of the application and updates the contents of subviews to reflect the selection in the master view. The master view controller has a reference to the detail view controller and informs the detail view controller whenever the selected item changes or some other relevant event occurs. The detail view controller might also serve as the split view controller’s delegate.

A complex application in which the master and detail views (and corresponding view controllers) may change. In complex configurations, you need a separate custom controller object to manage the master and detail view controllers and mediate between them. The custom controller is typically the split view controller’s delegate and is responsible for communicating with the current detail view controller to show and hide the popover bar button item.

The second one here is what you have, and in fact Apple provides a sample application called MultipleDetailViews that shows how to properly do this, which involves placing the delegate outside of the detail view controllers and having each of those detail view controllers conform to a protocol with at least two methods one to add the master button and one to remove the master button from the navigation bar (assuming you have a navigation bar in the detail view).

Make note that the "navigationbarbutton for the masterView" must always be shown and hidden in the detail view (and each and every one of them if you have more than one), because the master view is the one that's going to be hidden at times. This was another things that kept confusing me, because I kept thinking it belonged to the master view controller.

I'm guessing you may already have had all this worked out, but it helps to explain the actual answer to your question.


Your new detail view controller must check to see if you are being displayed in a UISplitView being presented in Portrait orientation and if so, present the button.


Just do this in the - (void)viewWillAppear:(BOOL)animated method and display it if needed. This does also mean that you either have to keep track of the button that was last hidden or build a new one.

Hope that helps, and if anyone reading this finds my logic wrong, please correct me. This still gets very confusing to me every time I find that button missing in my app.