Randall
Randall

Reputation: 2123

How to use UISplitViewController

I'm trying to use a split view controller to show a navigation controller on the left and a table view on the right. I use this code in RootViewController's viewDidLoad:

self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);

Settings *settings = [[Settings alloc] init]; //Table view
MainView *main = [[MainView alloc] init]; //Table view

UINavigationController *nav_con = [[UINavigationController alloc] init];
NSArray *controllers = [[NSArray alloc] initWithObjects:settings, detailViewController, nil];
[nav_con pushViewController:settings animated:NO];

self.view = nav_con.view;
detailViewController.view = main.view;

I've tried like a million different ways of coding this, and this one comes the closest to correct. It displays the navigation controller in the left pane and the main view in the right. HOWEVER, in the left pane, at the top, there are two bars with a big black space between them. One of the bars in my nav controller's bar. How can I just replace the content of the left pane entirely with my navigation controller's view?

Upvotes: 1

Views: 513

Answers (1)

bshirley
bshirley

Reputation: 8357

Settings and MainView better be subclasses of UITableViewController

the first object in controllers should be nav_con, not settings

delete the last two "view" lines,

and RootViewController should be a subclass of UISplitViewController and the instance that's being created should be set to window.rootViewController somewhere.

Also, it's fairly standard to do all this code external to viewDidLoad - makes me wonder what's being loaded as the view! Much easier to do all this in a nib file.

Upvotes: 1

Related Questions