1, the most common one of iOS layout, at the bottom of the tab navigation, control the different views.
2, the use of code to create Uitabbarcontroller.
1) in the Appdelegate
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
method, create a new Uitabbarcontroller, and then create a new Uiviewcontroller or uitableviewcontroller that you want. Use these views as the root view of the Uinavigationcontroller. Use Method Initwithrootviewcontroller.
2 Set the Uitabbarcontroller Viewcontrollers property, here is an array, you can set the previous Uinavigationcontroller in the array.
3) Gets the Tabbar property of the Uitabbarcontroller. Then create multiple uitabbaritem corresponding to the above view. Sets the title and image of the Uitabbaritem, corresponding to the headings and images respectively.
In the Tabbarcontroller can only put 4 tab, if more than 4, then will automatically generate a more tab, and then put the Extra tab in the more corresponding Tableviewcontroller view.
The code to create Uitabbarcontroller using code is as follows:
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {//Ove
Rride point for customization after application launch.
Maincontroller *maincontroller = [[Maincontroller alloc] init];
Basenavigationcontroller *mainnavctl = [self initlizernavigationcontrollerwithrootviewcontroller:maincontroller];
Maincontroller *maincontroller2 = [[Maincontroller alloc] init]; Basenavigationcontroller *MAINNAVCTL2 = [self initlizernavigationcontrollerwithrootviewcontroller:maincontroller2]
;
Maincontroller *maincontroller3 = [[Maincontroller alloc] init]; Basenavigationcontroller *MAINNAVCTL3 = [self Initlizernavigationcontrollerwithrootviewcontroller:maincontroller3]
;
Maincontroller *maincontroller4 = [[Maincontroller alloc] init]; Basenavigationcontroller *MAINNAVCTL4 = [self initlizernavigationcontrollerwithrootviewcontroller:maincontroller4]
; Set the bottom Tabbar Uitabbarcontroller *tab = [[[Uitabbarcontroller alloc] init];
Tab.viewcontrollers = @[mainnavctl,mainnavctl2,mainnavctl3,mainnavctl4];
Uitabbar *tabbar = Tab.tabbar;
Uitabbaritem *tabbaritem1 = [Tabbar.items objectatindex:0];
Uitabbaritem *tabbaritem2 = [Tabbar.items objectatindex:1];
Uitabbaritem *tabbaritem3 = [Tabbar.items objectatindex:2];
Uitabbaritem *tabbaritem4 = [Tabbar.items objectatindex:3];
tabbaritem1.title=@ "User";
Tabbaritem1.image=[uiimage imagenamed:@ "Github60"];
tabbaritem2.title=@ "position";
Tabbaritem2.image=[uiimage imagenamed:@ "github160"];
tabbaritem3.title=@ "Discovery";
Tabbaritem3.image=[uiimage imagenamed:@ "Github60"];
tabbaritem4.title=@ "More";
Tabbaritem4.image=[uiimage imagenamed:@ "more"];
Set the selected TabItem, or you can use Selectedviewcontroller//Tab.selectedindex = 2;
Self.window.rootviewcontroller=tab;
return YES; }
3. The way to create Uitabbarcontroller using storyboard is relatively simple.
1 in SB, select the Object view, select Tab Bar Controller, and drag to SB.
Now in SB you can see a tabbarcontroller corresponding to two Uiviewcontroller
2) New Viewcontroller or Tableviewcontroller. Select the first small dot at the top of the Tabbarcontroller view, use the control key to connect the new view, create a new segue in this way, and select View controllers under Relationship segue.
Use the above method to create a success. You can then define the title and imge of each tabbaritem directly in SB.