在实际的项目开发中总是有几个比较常见的模板,小编这几天给大伙出几期常用模板的博客,希望大家多提宝贵的意见! 这几个月最常用的莫过于Nav+UITabBar模板了;在实际的项目中,我比较侧重于纯代码,比较不喜欢拖控件,至于利弊在这里不多说了,言归正传。
First create a blank scene in APPDELEGATE.M:
Self.window=[[uiwindow Alloc]initwithframe:[[uiscreen Mainscreen]bounds]];
Initialize Uitabbarcontroller
Self.tabbarcontroller=[[uitabbarcontroller Alloc]init];
To create a two view controller:
Firstviewcontroller *one=[[firstviewcontroller Alloc]init];
Secondviewcontroller *second=[[secondviewcontroller Alloc]init];
Create two navigation controllers and have the two navigation controllers control the respective view controllers:
Uinavigationcontroller *navfirst=[[uinavigationcontroller Alloc]initwithrootviewcontroller:one];
Uinavigationcontroller *navsecond=[[uinavigationcontroller Alloc]initwithrootviewcontroller:second];
Let Tabbarcontroller include these two navigation controllers:
[Self.tabbarcontroller Addchildviewcontroller:navfirst];
[Self.tabbarcontroller Addchildviewcontroller:navsecond];
Tailor the individual view controllers to:
[Email protected] "contact";
One.tabbaritem=[[uitabbaritem alloc]initwithtitle:@ "One" Image:[uiimage imagenamed:@ ""]
Selectedimage:nil];
[Email protected] "collection";
Second.tabbaritem=[[uitabbaritem alloc]initwithtitle:@ "Second" Image:nil Selectedimage:nil];
The main view on the set blank scene is: Tabbarcontroller:
[Self.tabbarcontroller Addchildviewcontroller:navsecond];
Modify the scene to be red:
Self.window.backgroundcolor=[uicolor Redcolor];
Show Scene:
[Self.window makekeyandvisible];
Create a Level two page in Firstviewcontroller
To create a navigation bar:
Uibarbuttonitem *rightbutton=[[uibarbuttonitem Alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemsearch Target:self Action: @selector (selectrightaction:)];
To implement a jump method:
-(void) Selectrightaction: (ID) sender
{
Backviewcontroller *backbutton;
backButton=[[BackViewController alloc]initWithNibName:@"BackViewController" bundle:nil];backButton.[email protected]"第二视图层";[self.navigationController pushViewController:backButton animated:NO];
}
code example: http://download.csdn.net/detail/it_ds/8568545
Uitabbar+nav of the common template framework for iOS projects