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];

}

代码示例下载地址:http://download.csdn.net/detail/it_ds/8568545

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。