i want my splitviewController
to be displayed in within a TabBarController
. Unfortunately, I firstly decided to just have a SplitViewController
and chose apple's template. Now i am in the inconvenient position not knowing how to add it to a tab bar.
I tried several stuff that was explained here on StackOverflow but the best result was a black screen with a tab bar below it :-(
I am just struggling to find a nice and simple way.
Code of my Appdelegate
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the split view controller's view to the window and display.
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentFolderPath = [searchPaths objectAtIndex: 0];
self.rootViewController.directoryPath = documentFolderPath;
NSURL *docUrl = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
if ([docUrl isFileURL]) {
NSString *path = [docUrl path];
self.detailViewController.currentFilePath = path;
[self.detailViewController setDetails:path newFile:FALSE];
}
return YES;
You should check IntelligentSplitViewController is everything you need!
Adding some controllers and design you can end with something like this:
PS: I've actually have an app in the App Store using this controller so go head!
Edit:
i just realized you actually wanted a splitview inside the tabbar. per apple documentation, this is a no no. http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/iPadControllers/iPadControllers.html
A split view controller must always be the root of any interface you create. In other words, you must always install the view from aUISplitViewController object as the root view of your application’s window. The panes of your split-view interface may then contain navigation controllers, tab bar controllers, or any other type of view controller you need to implement your interface.
If you still want to use a tabbar the stuff i wrote below still applies, but your subview should not be a splitview controller.
original answer:
you'd create the tabbar controller in the code, then add the splitview controller as one of the tabs. in your case, self.splitViewController will become one of the view controllers inside your tabbar controller. I haven't tried this using an apple template app as a starting point, but give it should work.
you can look for tutorials on uitabbarcontroller for more information. This one looks promising: http://www.xcode-tutorials.com/uitabbarcontroller-and-uinavigationcontroller/
And this is handy too: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITabBarController_Class/Reference/Reference.html
heres a sample:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc] init];
//set tbconroller as root view controller of window
[self.window setRootViewController:tabBarController];
//window retains controller so we can release
[tabBarController release];
//create two view controllers
UIViewController *vc1 = [[HypnosisViewController alloc] init];
UIViewController *vc2 = [[CurrentTimeViewController alloc] init];
//make an array containing these two view controllers
NSArray *viewControllers = [NSArray arrayWithObjects:vc1,vc2,nil];
[tabBarController setViewControllers:viewControllers];
//the views are retained their new owners, so we can release
[vc1 release];
[vc2 release];
[[self window] makeKeyAndVisible];
return YES;
}
if you're using interface builder, here are a few more tutorials http://www.cimgf.com/2009/06/25/uitabbarcontroller-with-uinavigationcontroller-using-interface-builder/ or http://www.mobisoftinfotech.com/blog/iphone/iphone-tabbar-uitabbarcontroller-tutorial/
I just solved this issue as it has been running in my head background for the last couple of days. You can have as many "Split view" as you want inside a "UITabbarView" or vars versa, without using any code, but if you want to satisfy Apple and make the Split view controller is the root controller, you have to type one line of code.
So the beef is here.
Now, this final Storyboard should looks something like this. Again you don't have to start from Split view controller, but I did this just to match Apple recommendation.
From Apple's documentation this is a no no situation.
But there is a way to achieve this easily (we did it for an application).
have a look at http://www.codeworth.com/blog/mobile/ios-splitviewcontroller-inside-tabviewcontroller/
I think this would be the apt answer for the question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With