First, the basic concept of the tag bar controller
Uitabbarcontroller inherits from the view controller and manages the view controller in the form of a tab bar item, and the view controllers between the individual tab items are independent of each other and do not affect each other.
(1) The life cycle of each view controller in Uitabbarcontroller is consistent with the life cycle of Uitabbarcontroller;
(2) Click on different tab items (Uitabbaritem) to show the view of different views controller;
(3) The selected tab bar item corresponds to the view of the controller that is in the display state, and the other view controller's view is in the unloaded state.
Second, the advantages of the tag bar controller
(1) The application module, the low coupling between the modules, team Development Easy division of labor;
(2) The extension of the application is strong, can be selected according to the requirements of the increase, delete module.
Third, the creation of the tag bar control
Self.window =[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds]; Self.window.backgroundColor=[Uicolor Whitecolor]; [Self.window makekeyandvisible]; Rootviewcontroller*rootctrl =[[Rootviewcontroller alloc] init]; //creating a navigation controllerUinavigationcontroller *navctrl =[[Uinavigationcontroller alloc] Initwithrootviewcontroller:rootctrl]; Navctrl.title=@"Home Page"; //Create a ViewUiviewcontroller *VC1 =[[Uiviewcontroller alloc] init]; Vc1.title=@"Collection"; Uiviewcontroller*VC2 =[[Uiviewcontroller alloc] init]; Vc2.title=@"Search"; Uiviewcontroller*VC3 =[[Uiviewcontroller alloc] init]; Vc3.title=@"Set"; Nsarray*controllers =[Nsarray Arraywithobjects:navctrl,vc1,vc2,vc3,nil]; //create an instance of a tab bar controllerUitabbarcontroller *tabctrl =[[Uitabbarcontroller alloc] init]; //assigns an array of view controller instances to TabctrlTabctrl.viewcontrollers =controllers; //2nd View tab (Index starting from 0) is selected by defaultTabctrl.selectedindex=1; //Add the Tabbarcontroller view as a child to the windowSelf.window.rootViewController = Tabctrl;
Uitabbarcontroller (tab bar Controller)