#import <UIKit/UIKit.h> @interface TabBarViewController : UITabBarController + (TabBarViewController *)sharedTabBarController; @end #import "TabBarViewController.h" #import "FirstViewController.h" #import "SecondViewController.h" #import "ThirdViewController.h" @interface TabBarViewController () @end static TabBarViewController *_tabBarController; @implementation TabBarViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } + (TabBarViewController *)sharedTabBarController { if (_tabBarController == nil) { _tabBarController = [[TabBarViewController alloc]init]; } return _tabBarController; } - (id)init { self = [super init]; if (self) { FirstViewController *firVC = [[FirstViewController alloc]init]; firVC.title = @"First"; UINavigationController *firNaviController = [[UINavigationController alloc]initWithRootViewController:firVC]; SecondViewController *secVC = [[SecondViewController alloc]init]; secVC.title = @"Second"; UINavigationController *secNaviController = [[UINavigationController alloc]initWithRootViewController:secVC]; ThirdViewController *thiVC = [[ThirdViewController alloc]init]; thiVC.title = @"Third"; UINavigationController *thiNaviController = [[UINavigationController alloc]initWithRootViewController:thiVC]; firNaviController.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"First" image:nil tag:0]; secNaviController.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"Second" image:nil tag:1]; thiNaviController.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"Third" image:nil tag:2]; NSArray *controllerArray = [[NSArray alloc]initWithObjects:firNaviController,secNaviController,thiNaviController, nil]; self.viewControllers = controllerArray; } return self; }