Reputation: 2265
I am trying to replace the current view with a SplitViewController programatically. This is my code.
ProjectNavigationController *projectNavPanel = [[ProjectNavigationController alloc] init];
[projectNavPanel setProjectIndex:[indexPath row]];
[projectNavPanel setKuluId:[[[[[appDelegate userSettingsDictionary] objectForKey:@"Projects"] objectAtIndex:[indexPath row]] objectForKey:@"Kulu Id"] intValue]];
ProjectDetailController *projectDetailPanel = [[ProjectDetailController alloc] init];
[projectDetailPanel setProjectIndex:[indexPath row]];
ProjectSplitViewController *splitRootController = [[ProjectSplitViewController alloc] init];
[splitRootController setViewControllers:[NSArray arrayWithObjects:projectNavPanel, projectDetailPanel, nil]];
[[self view] removeFromSuperview];
[[appDelegate window] setRootViewController:splitRootController];
This is almost working fine, with one exception. When the split view controller is loaded and in portrait mode, the navigation view hides - as expected - but the detail view has no toolbar with a button to show the navigation in a popover view. From my research, i understood this was the default behaviour. Am I missing something? There is very little in the detailViewController so I have not included the code here, but if it helps, let me know.
Upvotes: 0
Views: 405
Reputation: 7161
There are some things missing in your code;
First, to have the navigationbar to add the button to, you have to have a UINavigationController
in between your UISplitViewController
and your ProjectDetailController
.
Second, you have to setup a UISplitViewControllerDelegate and use the delegate methods to add the button:
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
[[projectDetailPanel navigationItem] setLeftBarButtonItem:barButtonItem animated:YES];
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
[[projectDetailPanel navigationItem] setLeftBarButtonItem:nil animated:YES];
}
And third, don't forget to set the title to your ProjectNavigationController
, or set a title manually to the barButtonItem
in the splitViewController:willHideViewController:withBarButtonItem:forPopoverController
method you just implemented.
Upvotes: 1