Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 20, 2011, 02:41 PM   #1
sparkymark75
macrumors newbie
 
Join Date: Jan 2011
Noob help with UISplitViewController

Hi,

I'm new to Objective-C (coming from C#) so I'm slowly getting my head around things. Anyway, one thing I'm really struggling with is embedding a TabBar within the DetailsView of a SplitView.

It seems every guide/article I find on this is people asking how to do the opposite, embed a SplitView within a TabBar

So far I've actually managed to get the TabBar in the DetailsView area of the SplitView however I'm not sure if it's the correct way to do it and there are a couple of issues.

First, I'll describe how I got to where I am;
  1. Create a new app using the built-in XCode SplitView template.
  2. Create a new app using the built-in XCode TabBar template.
  3. Copy the .xib, .h and .m files for the FirstView and SecondView controllers from the TabBar app into the SplitView app.
  4. Discarded the TabBar project as it's no longer required. All other steps are carried out in the SplitView project.
  5. Added the following code to my application delegate header file;
    Code:
    @class RootViewController;
    @class DetailViewController;
    @class FirstViewController;
    @class SecondViewController;
    
    @interface SplitViewTemplateAppDelegate : NSObject <UIApplicationDelegate> {
    
        UIWindow *window;
    
        UISplitViewController *splitViewController;
        UITabBarController *tabBarController;
    
        RootViewController *rootViewController;
        DetailViewController *detailViewController;
        FirstViewController *firstViewController;
        SecondViewController *secondViewController;
    }
    
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    
    @property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
    @property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
    @property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;
    @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    @property (nonatomic, retain) IBOutlet FirstViewController *firstViewController;
    @property (nonatomic, retain) IBOutlet SecondViewController *secondViewController;
  6. Opened up MainWindow.xib in IB and changed the class on the DetailsView to UITabController
  7. Added the following code to my application delegate module file;
    Code:
    #import "FirstViewController.h"
    
    @synthesize window, splitViewController, rootViewController, detailViewController, tabBarController, firstViewController, secondViewController;
    
    -(void) makeTabBarController {
        NSMutableArray *controllers = [NSMutableArray arrayWithArray:splitViewController.viewControllers];
        int index = 0; 
        for (UIViewController *controller in splitViewController.viewControllers) {
            if (index == 1) {
    
                //NSLog(@"Index is: %@", index);
                //NSLog(@"Controller name is: %@", controller.title);
    
                UINavigationController *localNavController;
                tabBarController = [[UITabBarController alloc] init];
                NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:2];
    
                firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:nil];
                localNavController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
                localNavController.tabBarItem.title = @"First Tab";
                [firstViewController release];
    
                [localViewControllersArray addObject:localNavController];
                [localNavController release]; // Retained by above array
    
                secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil];
                localNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
                localNavController.tabBarItem.title = @"Second Tab";
                [secondViewController release];
    
                [localViewControllersArray addObject:localNavController];
                [localNavController release]; // Retained by above array
    
                tabBarController.viewControllers = localViewControllersArray;
                [localViewControllersArray release]; // Retained thru above setter
    
                //tabBarController.delegate = splitViewController;
                [controllers replaceObjectAtIndex:index withObject:tabBarController];
            }
            index++;
        }
        splitViewController.viewControllers = controllers;
    }
  8. Added
    Code:
    [self makeTabBarController];
    to the didFinishLaunchingWithOptions method.

So now I get an out of the box SplitView with a tab bar controller on the right with two tabs in it. The tabs work for switching between the views.

A couple of things that I am now struggling with are;
  • The button to fire the Popover is missing, do I need to add this to each tab view?
  • How do I hook the RootViewController with the TabBarController so that details for the selected item is shown?
sparkymark75 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
General: iFile noob Sovahkiin Jailbreaks and iOS Hacks 4 Mar 27, 2013 06:13 PM
UISplitViewController in iPhone mikezang iPhone/iPad Programming 8 Feb 28, 2013 01:29 AM
Handbrake Noob: Help ZmyDust Mac Applications and Mac App Store 6 Feb 17, 2013 10:54 PM
iPhone: Help a Noob JB iphone 4s 6.0.1 deoxyribo Jailbreaks and iOS Hacks 2 Nov 7, 2012 08:42 PM
Sorry - another noob... tallbutslow MacBook Air 1 Jun 14, 2012 05:53 PM

Forum Jump

All times are GMT -5. The time now is 09:14 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC