UISplitViewController: how to get toolbar if detai

2019-06-12 04:56发布

问题:

I checked out Apple's example on how to exchange detail views in the UISplitViewController and it seems that they put the UIToolbar in every detail controller. Then, if the device is rotated, they hide the toolbar or show it and add a popover button which will show the root controller.

I'd like to adopt this pattern to show my root controller in a popover using a button in the toolbar, but unfortunately, my detail controllers are all UITableViewControllers and they do not allow adding other UI elements than a table view. So how do I deal with that? Is there an example around?

René

回答1:

I think I figured out by myself: DON'T use a ´UITableViewController´ and a UITableView as root view in your NIB, as you cannot add a UIToolbar to the table view.

Instead: In the NIB, put a standard view and drag a UIToolbar and a UITableView on it. Connect the standard view to the controller's "view" outlet. Add another outlet and make it a UITableView. Connect the table view to it.

In the code: Let your controller inherit from UIViewController and not from UITableViewController. Add a property to your controller to get the TableView to make it look compatible to UITableViewController.

public UITableView TableView
{
get { return this.viewTableView; }
}

Upon the viewDidRotate event you will have to adjust the table views width and height now (UITableViewController did that job for you before):

this.TableView.Frame = new RectangleF(0, 44, this.SuperView.Frame.Width, this.SuperView.Frame.Height);

The 44 pixels com from the parent view's toolbar.

I don't miss UITableViewController. I know there are some issues like automatic scrolling when editing, but in my case this is simply not needed.

René



回答2:

Check out this example and the corresponding code. If I understand your question, this should show you how to do what you're looking to accomplish.

Also, just as an FYI to everyone, another MT user MonoTouched the MultipleDetailViews example that you linked to above.