Reputation: 2487
I started with a Master-Detail Application, then went to the iPhone storyboard
, selected the NavigationController
and went to Editor > Embed In > TabBarController
and it worked just fine. When I tried to do the same in the iPad storyboard
the Embed in TabBarController
menu item was disabled. Should I just do that manually?
Upvotes: 1
Views: 4659
Reputation: 3218
Based on Rob George's Swift answer, here is the Objective-C code:
UITabBarController *tabBarViewController= (UITabBarController *) self.window.rootViewController;
NSLog(@"%lu",tabBarViewController.viewControllers.count);
UISplitViewController *splitViewController = (UISplitViewController *)nil;
for(UIViewController *viewController in tabBarViewController.viewControllers){
if([viewController.title isEqualToString:@"Master"]){
splitViewController= (UISplitViewController *) viewController;
}
}
UINavigationController *navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1];
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
splitViewController.delegate = self;
Took me a while because "first" ViewController was white and with the bar (with no icons and white text) being almost perfectly white, too, I thought the app just defaults to displaying nothing but actually it was picking the ViewController that was empty and I simply didn't see the bar. Just in case you were wondering why it doesn't work lol
Upvotes: 1
Reputation: 126
In the app delegate replace the reference to the splitViewController as follows.
let tabBarViewController = self.window!.rootViewController as! UITabBarController
print(tabBarViewController.viewControllers?.count)
var splitViewController:UISplitViewController? = nil
for viewController in tabBarViewController.viewControllers! {
if viewController.title == "Master" {
splitViewController = viewController as? UISplitViewController
}
}
let navigationController = splitViewController!.viewControllers[splitViewController!.viewControllers.count-1] as! UINavigationController
navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController!.displayModeButtonItem()
splitViewController!.delegate = self
Upvotes: 7
Reputation: 2072
The Split View Controller can't be embedded into anything - it needs to be the root view controller in your storyboard.
You can however select either the Master View Controller or the Detail View Controller and embed those classes into other view controllers.
Upvotes: 0
Reputation: 2330
In my application I embed programmatically like below
UISplitViewController *split=[[UISplitViewController alloc]init];
PatientListController *patListContr=[[PatientListController alloc]init];
PatientController *patientControl=[[PatientController alloc]init];
split.viewControllers=@[patListContr,patientControl];
split.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"" image:[UIImage imageNamed:@"patient.png"] selectedImage:nil];
Then embed the above split view controller to a TabbarController
UITabBarController *tabbarContr=[[UITabBarController alloc]init];
tabbarContr.viewControllers=@[split,yourController1,yourController2];
Upvotes: 1