在實際的項目開發中總是有幾個比較常見的模板,小編這幾天給大伙出幾期常用模板的博客,希望大家多提寶貴的意見!
這幾個月最常用的莫過於Nav+UITabBar模板了;在實際的項目中,我比較側重於純代碼,比較不喜歡拖控件,至於利弊在這裡不多說了,言歸正傳。
首先在AppDelegate.m中創建一個空白布景:
self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
初始化UITabBarController
self.tabBarController=[[UITabBarController alloc]init];
創建兩個視圖控制器:
FirstViewController *one=[[FirstViewController alloc]init];
SecondViewController *second=[[SecondViewController alloc]init];
創建兩個導航控制器並 讓這兩個導航控制器控制好各自的視圖控制器:
UINavigationController *navFirst=[[UINavigationController alloc]initWithRootViewController:one];
UINavigationController *navSecond=[[UINavigationController alloc]initWithRootViewController:second];
讓tabBarController包含這兩個導航控制器:
[self.tabBarController addChildViewController:navFirst];
[self.tabBarController addChildViewController:navSecond];
對各自的視圖控制器進行細膩化的定制:
one.title=@”聯系人”;
one.tabBarItem=[[UITabBarItem alloc]initWithTitle:@”one” image:[UIImage imageNamed:@”“]
selectedImage:nil];
second.title=@”收藏”;
second.tabBarItem=[[UITabBarItem alloc]initWithTitle:@”second” image:nil selectedImage:nil];
設置改空白布景上的主視圖為:tabBarController:
[self.tabBarController addChildViewController:navSecond];
修改布景為紅色:
self.window.backgroundColor=[UIColor redColor];
顯示布景:
[self.window makeKeyAndVisible];
在FirstViewController中創建二級頁面
創建導航欄:
UIBarButtonItem *rightButton=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(selectRightAction:) ];
實現跳轉方法:
-(void)selectRightAction:(id)sender
{
BackViewController *backButton;
backButton=[[BackViewController alloc]initWithNibName:@BackViewController bundle:nil];
backButton.title=@第二視圖層;
[self.navigationController pushViewController:backButton animated:NO];
}