Background conditions are
One of the root controllers is inherited from Uitabbarcontroller
and build four Uiviewcontroller.
And then create a uiviewcontroller we make it as a sub-interface of one of the top four
And then write the following code in Rootviewcontroller
#import "WJJRootViewController.h" #import "WJJFirstViewController.h" #import "WJJSecondViewController.h" #import " WJJThirdViewController.h "#import" WJJForthViewController.h "@interface Wjjrootviewcontroller () @end @implementation wjjrootviewcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [Super I Nitwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;} /* tab bar is more advanced than the navigation bar Viewcontroller has a tab bar app first to see a few tags and then create a few Uiviewcontroller if uiviewcontroller in the navigation bar to create a navigation bar, Let Uiviewcontroller as the navigation bar Rootviewcontroller */-(void) viewdidload{[Super viewdidload];//do no additional setup after L Oading the view. [Self createviewcontrollers]; }-(void) createviewcontrollers{//Instantiate each Uiviewcontroller Wjjfirstviewcontroller * first = [[Wjjfirstviewcontrolle R Alloc] Init]; Add a navigation bar for each viewcontroller Uinavigationcontroller * Firstnav = [[Uinavigationcontroller alloc] InitwithrootviewcontRoller:first]; Instantiate first's item system Tabbar Select Yes Blue is fixed color immutable first.tabbaritem = [[Uitabbaritem alloc] initwithtitle:@ "" Image: [UIImage imag enamed:@ "Tab_0.png"] selectedimage:[uiimage imagenamed:@ "Tab_c0.png"]; Other three interface Wjjsecondviewcontroller * second = [[Wjjsecondviewcontroller alloc] init]; Second.tabbaritem = [[Uitabbaritem alloc] initwithtitle:@ "Contacts" Image: [UIImage imagenamed:@ "Tab_1.png"] SelectedImage: [UIImage imagenamed:@ "Tab_c1.png"]; Wjjthirdviewcontroller * third = [[Wjjthirdviewcontroller alloc] init]; Third.tabbaritem = [[Uitabbaritem alloc] initwithtitle:@ "discovery" Image: [UIImage imagenamed:@ "Tab_2.png"] selectedimage:[ UIImage imagenamed:@ "Tab_c2.png"]; Wjjforthviewcontroller * four = [[Wjjforthviewcontroller alloc] init]; Four.tabbaritem = [[Uitabbaritem alloc] initwithtitle:@ "Settings" Image: [UIImage imagenamed:@ "Tab_3.png"] selectedimage:[ UIImage imagenamed:@ "Tab_c3.png"]; Add a navigation bar for each viewcontroller Uinavigationcontroller * SecoNdnav = [[Uinavigationcontroller alloc] initwithrootviewcontroller:second]; Uinavigationcontroller * Thirdnav = [[Uinavigationcontroller alloc] initwithrootviewcontroller:third]; Uinavigationcontroller * Fournav = [[Uinavigationcontroller alloc] initwithrootviewcontroller:four]; Put the created four nav into the container in the tab bar self.viewcontrollers = @[firstnav,secondnav,thirdnav,fournav]; Let the first interface as the initial page self.selectedindex = 0;} -(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
Then initialize a background color for each Uiviewcontroller
Next, let the first interface be tuned to the sub-interface three other similar practices
Enter the FIRSTVIEWCONTROLLER.M
#import "WJJFirstViewController.h" #import "WJJFirstChildViewController.h" @interface Wjjfirstviewcontroller () @ End@implementation wjjfirstviewcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;} -(void) viewdidload{[Super viewdidload];//do any additional setup after loading the view. Self.view.backgroundColor = [Uicolor Redcolor]; Navigation Bar and Tab bar if there are simultaneous calls to the following method will make the navigation bar title and the item title of the label into the following string//self.title = @ "I am snail"; So use the following statement to add a caption for the navigation bar Self.navigationController.title = @ "Snail"; The simulation shows a few days of unread information in the upper-right corner of the two words self.tabBarItem.badgeValue = @ "5"; [Self Createbutton];} Add a sub-interface for the first interface wjjfirstchildviewcontroller.m-(void) createbutton{UIButton * Rightbutton = [UIButton buttonwithty Pe:uibuttontypesystem]; Rightbutton.frame = CGRectMake (0, 0, 50, 20); [Rightbutton settitle:@ "Next page" Forstate:uiControlstatenormal]; [Rightbutton addtarget:self Action: @selector (NextPage) forcontrolevents:uicontroleventtouchupinside]; Uibarbuttonitem * Rightbarbuttonitem = [[Uibarbuttonitem alloc] Initwithcustomview:rightbutton]; Self.navigationItem.rightBarButtonItem = Rightbarbuttonitem;} -(void) nextpage{Wjjfirstchildviewcontroller * child = [[Wjjfirstchildviewcontroller alloc] init]; [Self.navigationcontroller Pushviewcontroller:child Animated:yes]; }-(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
And then into Firstviewcontroller's sub-interface firstchildviewcontroller.m.
#import "WJJFirstChildViewController.h" @interface Wjjfirstchildviewcontroller () @end @implementation wjjfirstchildviewcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{ self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) { //Custom initialization } return to self;} -(void) viewdidload{ [Super viewdidload];//do any additional setup after loading the view. Self.view.backgroundColor = [Uicolor cyancolor];} Call period function when entering this sub-interface, the tab bar is hidden-(void) Viewwillappear: (BOOL) animated{ [Super viewwillappear:animated]; Self.tabBarController.tabBar.hidden = YES;} When this page disappears, the tab bar appears-(void) Viewwilldisappear: (BOOL) animated{ [Super viewwilldisappear:animated]; Self.tabBarController.tabBar.hidden = NO;} -(void) didreceivememorywarning{ [Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
As follows: Main interface jump
Jump to sub-interface
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Snail-ui Learning System tab Bar Uitabbarcontroller