ios項目常用模板架構之UITabBar+Nav

來源:互聯網
上載者:User

ios項目常用模板架構之UITabBar+Nav

 在實際的項目開發中總是有幾個比較常見的模板,小編這幾天給大夥出幾期常用模板的部落格,希望大家多提寶貴的意見!  這幾個月最常用的莫過於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];

}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.