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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Help with port forwarding for Security software? PPFee Mac Applications and Mac App Store 1 Dec 11, 2011 03:34 PM
help with dragging a UIImageView on screen mandude iPhone/iPad Programming 3 Nov 28, 2011 12:05 PM
help with excel for mac 2008 damiang72 Mac Applications and Mac App Store 0 Nov 14, 2010 06:19 AM
NOOB HELP with Widgets felipson Mac Basics and Help 4 Dec 16, 2006 08:11 PM
Need some basic noob help with mac :) truz Mac Basics and Help 13 Jan 22, 2006 11:42 PM


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

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

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