Here is the simplest way to make Split Controller in Ta Bar Controller.
1. Use Template SplitViewController to Make a project named TemplateSplit and compile it.
2. Use Template TabBarController to make a project named SplitInTabBar and compile it.
3. Add files RootViewController.*, DetailViewController.*, DetailView.xib of project TemplateSplit to project SPlitInTabBar.
4. Add a new tab in project SplitInTabBar.
5. Add code as below to file SplitInTabBarAppDelegate.h.
6。Add code as below to file SplitInTabBarAppDelegate.m.
1. Use Template SplitViewController to Make a project named TemplateSplit and compile it.
2. Use Template TabBarController to make a project named SplitInTabBar and compile it.
3. Add files RootViewController.*, DetailViewController.*, DetailView.xib of project TemplateSplit to project SPlitInTabBar.
4. Add a new tab in project SplitInTabBar.
5. Add code as below to file SplitInTabBarAppDelegate.h.
Code:
#import <UIKit/UIKit.h>
[B]@class RootViewController;
@class DetailViewController;[/B]
@interface SplitInTabBarAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
[B] UISplitViewController *splitViewController;
RootViewController *rootViewController;
DetailViewController *detailViewController;[/B]
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
[B]@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
@property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;[/B]
@end
6。Add code as below to file SplitInTabBarAppDelegate.m.
Code:
#import "SplitInTabBarAppDelegate.h"
[B]#import "RootViewController.h"
#import "DetailViewController.h"[/B]
@implementation SplitInTabBarAppDelegate
@synthesize window;
@synthesize tabBarController;
[B]@synthesize splitViewController;
@synthesize rootViewController;
@synthesize detailViewController;[/B]
#pragma mark -
#pragma mark Application lifecycle
[B]-(void) makeSplitViewController {
NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
int index = 0;
for (UIViewController *controller in tabBarController.viewControllers) {
if (index == 2) {
detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
rootViewController.detailViewController = detailViewController;
rootViewController.navigationItem.title = @"List";
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
splitViewController = [[UISplitViewController alloc] init];
splitViewController.tabBarItem = controller.tabBarItem;
splitViewController.viewControllers = [NSArray arrayWithObjects:nav, detailViewController, nil];
splitViewController.delegate = detailViewController;
[controllers replaceObjectAtIndex:index withObject:splitViewController];
}
index++;
}
tabBarController.viewControllers = controllers;
}[/B]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
[B][self makeSplitViewController];[/B]
// Add the tab bar controller's current view as a subview of the window
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
return YES;
}