Storyboard is a powerful tool for writing code that helps you to layout connections between multiple views, both visually and by reducing the amount of code, but as a programmer, pure code writing is a necessary skill without the use of storyboard.
The following is pure code implementation of pure code implementation of the Uitabbarcontroller view switch function, we realize the conversion between three views, the code is not much, easy to see understand.
Steps:
1. Delete Storyboard Storyboard and Uiviewcontroller
2, the creation of three controller classes, are inherited from Uiviewcontroller, respectively, Firstviewcontroller, Secondviewcontroller, Threeviewcontroller
3, in order to facilitate the separation of the view of the jump, respectively, in the above three controller classes to set their respective view color.
4, the creation of these three controllers, the creation of Uitabbarcontroller, the creation of windows in the Appdelegate application proxy class. Finally, the integration of the code can be.
The file is as follows:
The demo results are as follows:
The code is as follows:
Only set the view color in the Firstviewcontroller class:
1 -(void) viewdidload {2 [Super Viewdidload]; 3 // set the view color 4 Self.view.backgroundColor = [Uicolor redcolor]; 5 }
Only set the view color in the Secondviewcontroller class
1 -(void) viewdidload {2 [Super Viewdidload]; 3 // set the view color 4 Self.view.backgroundColor = [Uicolor greencolor]; 5 }
Only set the view color in the Threeviewcontroller class
1 -(void) viewdidload {2 [Super Viewdidload]; 3 // set the view color 4 Self.view.backgroundColor = [Uicolor purplecolor]; 5 }
In the Appdelegate application proxy class, the code is the focus, as follows:
1 #import "AppDelegate.h"2 #import "FirstViewController.h"3 #import "SecondViewController.h"4 #import "ThreeViewController.h"5 6 @interfaceappdelegate ()7 8 @end9 Ten @implementationappdelegate One A --(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions { - //Create window and set size theSelf.window =[[UIWindow Alloc]initwithframe:[[uiscreen Mainscreen]bounds]]; - - //Create Uitabbarcontroller -Uitabbarcontroller *tabbarcontroller =[[Uitabbarcontroller alloc]init]; + - //create three controllers and join Tabbarcontroller +Firstviewcontroller *FIRSTVC =[[Firstviewcontroller alloc]init]; A //set Tab bar title atFirstVC.tabBarItem.title =@" First"; - //set the system's own icon -Firstvc.tabbaritem = [[Uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemfavorites tag:0]; - //Set Badgevalue -FirstVC.tabBarItem.badgeValue =@"Ten"; - inSecondviewcontroller *SECONDVC =[[Secondviewcontroller alloc]init]; -SecondVC.tabBarItem.title =@"Second"; to //set the system's own icon +Secondvc.tabbaritem = [[Uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemdownloads tag:1]; - //Set Badgevalue theSecondVC.tabBarItem.badgeValue =@"5"; * $ Panax NotoginsengThreeviewcontroller *THREEVC =[[Threeviewcontroller alloc]init]; -ThreeVc.tabBarItem.title =@"three"; the //set the system's own icon +Threevc.tabbaritem = [[Uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitembookmarks tag:2]; A the //[Tabbarcontroller ADDCHILDVIEWCONTROLLER:FIRSTVC]; + //[Tabbarcontroller ADDCHILDVIEWCONTROLLER:SECONDVC]; - //[Tabbarcontroller ADDCHILDVIEWCONTROLLER:THREEVC]; $Tabbarcontroller.viewcontrollers =@[firstvc,secondvc,threevc]; $ - //To set Tabbarcontroller as the root controller -Self.window.rootViewController =Tabbarcontroller; the - //window accepts the user response and displaysWuyi [Self.window makekeyandvisible]; the - returnYES; Wu}
IOS: Delete Storyboard, pure code implementation Uitabbarcontroller View switching function