Search code examples
iosipaduitabbarcontrolleruisplitviewcontrollerios5.1

How can I create a UISplitViewController in my tab bar application (iPad)?


I have seen several apps that make use of a UISplitViewController inside a tab. This is exactly what I need to do however I'm having several issues.

So far I have done the following:

In my app delegate class...

// Set up the cuts tab
UIViewController *splitViewController = [[SplitViewController alloc] initWithNibName:@"SplitViewController" bundle:nil];

// Set up the tab bar
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:splitViewController, nil];

Then in the SplitViewController.h is have...

#import <UIKit/UIKit.h>

@class LeftView;
@class RightView;

@interface SplitViewController : UIViewController
{
    UISplitViewController *splitView;
    LeftView *leftView;
    RightView *rightView;
}


@property(nonatomic, retain)IBOutlet UISplitViewController *splitView;
@property(nonatomic, retain)IBOutlet LeftView *leftView;
@property(nonatomic, retain)IBOutlet RightView *rightView;


@end

Then in the corresponding .m file I have ...

#import "SplitViewController.h"

@implementation SplitViewController
@synthesize splitView, leftView, rightView;

#pragma mark - View Lifecycle

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        self.title = @"Tab A";
        self.tabBarItem.image = [UIImage imageNamed:@"My_Icon"];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view = splitView.view;
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    self.splitView = nil;
    self.leftView = nil;
    self.rightView = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

@end

The next thing I did was to create a UITableViewController class for leftView and a UIViewController class for rightView.

Finally I linked up the IBOutlets to the corresponding components and tried running it. However, when I run the app all is see is a black screen where I would expect to see the UISplitViewController.

I'm completely stumped at this point so any help would be really appreciated.

FURTHER INFO:

To be more specific I have been following this tutorial up to the section 'Making Our Model', where I stopped because the UISplitView wasn't being displayed.


Solution

  • Check out the IntelligentSplitViewController.