Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabBarController and SplitViewController

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;
like image 969
Faser Avatar asked Oct 31 '11 10:10

Faser


4 Answers

You should check IntelligentSplitViewController is everything you need!

Adding some controllers and design you can end with something like this:

Screenshot of an iPad app using IntelligentSplitViewController

PS: I've actually have an app in the App Store using this controller so go head!

like image 59
3lvis Avatar answered Oct 29 '22 18:10

3lvis


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/

like image 20
Mark Avatar answered Oct 29 '22 20:10

Mark


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.

  1. Create one single view project, or what ever you like.
  2. In the Main Storyboard drag and drop split view controller.
  3. Drag the initialising arrow from the "single view controller" and appoint it to the your "split view Controller".
  4. Now if you run your project you it should loads the split view.
  5. Create new coca touch file subclass of "UISplitViewController", call it whatever you like.
  6. In "viewDidLoad" add the following line "self.preferredDisplayMode = .PrimaryHidden" // just to hide the master view
  7. Back you the Main storyboard select the Split view controller and make it's view controller the one you just created.
  8. Now, delete the "View" of the details view controller (just the view)
  9. Find the "Container view" in the objects library, drag it and drop it in the details view controller.
  10. This will generates view controller connected to the "Container View" Embed the generated view controller in "Tab Bar Controller" Now, you have Split View connected to Tab Bar controller.
  11. Your TabBarController should have one view controller (item 1), replace the the "view" (only view) of the this controller with "ContainerView".
  12. Now drag and drop new Split view controller from the "Objects library" Connect the "ContainerView" in "Item 1" to the new added "Split view controller".
  13. Now, if you recall we should have one view controller hanging somewhere around, as we created single view project, find that controller connect it to the the tab bar controller, so now you have 2 items.
  14. Repeat the same process, replace the view with "container view" and add new split view controller and connect it to this story boards.

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.

enter image description here

enter image description here

like image 3
Ofcourse Avatar answered Oct 29 '22 19:10

Ofcourse


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.

like image 2
RamaKrishna Chunduri Avatar answered Oct 29 '22 20:10

RamaKrishna Chunduri