Combination of iOS navigation controller and tag bar Controller
-(Void) initTabBar {// initialize the Home Page HomePageViewController * homePage = [[HomePageViewController alloc] init]; UINavigationController * handle = [[UINavigationController alloc] handle: homePage]; // determine whether the city in which the user stores NSUserDefaults * userDefault = [NSUserDefaults standardUserDefaults]; if (! [UserDefault objectForKey: @ "cityDic"]) {CitySelectionViewController * citySelection = [[CitySelectionViewController alloc] init]; [homePageNav pushViewController: citySelection animated: YES];} // set homepage-TabBar UITabBarItem * itemHomePage = [[UITabBarItem alloc] initWithTitle: @ "Homepage" image: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.png"] scaledToSize: CGSizeMake (25, 25)] tag: 0]; [itemHomePage usage: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.jpg"] scaledToSize: CGSizeMake (25, 25)] usage: [UIImage imageWithImage: [UIImage imageNamed: @ "1-2.jpg"] scaledToSize: CGSizeMake (25, 25)]; homePageNav. tabBarItem = itemHomePage; [itemHomePage failed: [NSDictionary failed: NAVBACKGROUNDCOLOR, failed, nil] forState: UIControlStateSelected]; if (failed ([NSString stringWithFormat: @ "7.0"]) {[homePageNav. navigationBar setBarTintColor: NAVBACKGROUNDCOLOR];} else {[homePageNav. navigationBar setTintColor: NAVBACKGROUNDCOLOR];} homePageNav. navigationBar. translucent = NO; // initialize my shopping carshoppingcartviewcontroller * shoppingCart = [[ShoppingCartViewController alloc] init]; UINavigationController * handle = [[UINavigationController alloc] handle: shoppingCart]; // set shopping cart-TabBar UITabBarItem * items = [[UITabBarItem alloc] initWithTitle: @ "my shopping cart" image: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.png"] scaledToSize: CGSizeMake (25, 25)] tag: 0]; [itemShoppingCart handle: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.jpg"] scaledToSize: CGSizeMake (25, 25)] labels: [UIImage imageWithImage: [UIImage imageNamed: @ "1-2.jpg"] scaledToSize: CGSizeMake (25, 25)]; shoppingCartNav. tabBarItem = itemShoppingCart; [itemShoppingCart attributes: [NSDictionary attributes: NAVBACKGROUNDCOLOR, attributes, nil] forState: UIControlStateSelected]; if (attributes ([NSString stringWithFormat: @ "7.0"]) {[shoppingCartNav. navigationBar setBarTintColor: NAVBACKGROUNDCOLOR];} else {[shoppingCartNav. navigationBar setTintColor: NAVBACKGROUNDCOLOR];} shoppingCartNav. navigationBar. translucent = NO; // initialize our consumer * individualCenter = [[Alibaba alloc] init]; UINavigationController * handle = [[UINavigationController alloc] initWithRootViewController: individualCenter]; // set huizhong-TabBar UITabBarItem * region = [[UITabBarItem alloc] initWithTitle: @ "My happy home" image: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.png"] scaledToSize: CGSizeMake (25, 25)] tag: 0]; [itemindividualCenter usage: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.jpg"] scaledToSize: CGSizeMake (25, 25)] usage: [UIImage imageWithImage: [UIImage imageNamed: @ "1-2.jpg"] scaledToSize: CGSizeMake (25, 25)]; individualCenterNav. tabBarItem = itemindividualCenter; [itemindividualCenter feature: [NSDictionary feature: NAVBACKGROUNDCOLOR, rule, nil] forState: UIControlStateSelected]; if (feature ([NSString stringWithFormat: @ "7.0"]) {[individualCenterNav. navigationBar setBarTintColor: NAVBACKGROUNDCOLOR];} else {[individualCenterNav. navigationBar setTintColor: NAVBACKGROUNDCOLOR];} individualCenterNav. navigationBar. translucent = NO; self. tabBar = [[UITabBarController alloc] init]; [[UITabBar appearance] setBackgroundImage: [UIImage layout: COLOR (255,255,255, 1) withFrame: RectWithPara (0, 0, SCREEN_WIDTH, 44)]; // set the UITabBar background image [[UITabBar appearance] setSelectionIndicatorImage: [UIImage imageWithTint: COLOR (235,235,235, 1)]; self. tabBar. viewControllers = [NSArray arrayWithObjects: homePageNav, shoppingCartNav, individualCenterNav, nil];}
Set the root controller to tabbar when the program starts, as shown below:
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
{
Self. window = [[uiappswalloc] initWithFrame: [UIScreenmainScreen] bounds];
[SelfinitTabBar];
Self. window. rootViewController = self. tabBar;
Self. window. backgroundColor = [UIColorwhiteColor];
[Self. windowmakeKeyAndVisible];
Return YES;
}