iOS学习笔记——导航栏与标签栏结合
来源:互联网 发布:手机号码短信接收软件 编辑:程序博客网 时间:2024/06/14 21:51
1.直接在根视图控制器上显示标签栏和导航栏
只有一个根视图控制器,在AppDelegate.m文件中的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)lanuchOptions方法中添加如下代码:
//创建导航栏对象 UINavigationController *pNavigation = [[UINavigationController alloc]initWithRootViewController:self.viewController]; //创建另外一个类的对象 LinAnotherViewController * pAnotherVC = [[LinAnotherViewController alloc]initWithNibName:nil bundle:nil]; //创建Tabbar对象 UITabBarController *pTabBar = [[UITabBarController alloc]init]; //初始化数组,存储标签栏的内容 NSArray *pArray = [NSArray arrayWithObjects:pNavigation,pAnotherVC, nil]; //把数组中内容传递给标签栏控制器 pTabBar.viewControllers = pArray; //设置根视图控制器 self.window.rootViewController = pTabBar;
此时视图都为空,可按照之前学习的方法添加相应的控件、图片、设置导航栏、标签栏的属性等。
2.新建根视图控制器,显示切换界面后的标签栏和导航栏
当需要在页面跳转后显示标签栏和导航栏,此时应该设置新的根视图,在它上面编写创建相应的视图控制器、导航栏,再添加到标签栏控制器中。需要实现AppDelegate的委托创建新的根视图。
首先是导入新视图的名称,特别是:LinAppDelegate.h文件。
#import "LinFirstViewController.h"#import "LinSecondViewController.h"#import "LinThirdViewController.h"//委托协议代理#import "LinAppDelegate.h"重写- (void)viewDidLoad方法:
- (void)viewDidLoad{ [super viewDidLoad]; //创建视图对象和相应的导航栏对象,假设均有导航栏 LinFirstViewController * pFirstVC = [[LinFirstViewController alloc]initWithNibName:nil bundle:nil]; UINavigationController * pFirstNavigation = [[UINavigationController alloc]initWithRootViewController:pFirstVC]; LinSecondViewController * pSecondVC = [[LinSecondViewController alloc]initWithNibName:nil bundle:nil]; UINavigationController * pSecondNavigation = [[UINavigationController alloc]initWithRootViewController:pSecondVC]; LinThirdViewController * pThirdVC = [[LinThirdViewController alloc]initWithNibName:nil bundle:nil]; UINavigationController * pThirdNavigation = [[UINavigationController alloc]initWithRootViewController:pThirdVC]; //初始化数组,存储导航控制器 NSArray * array = [[NSArray alloc]initWithObjects:pFirstNavigation, pSecondNavigation, pThirdNavigation, nil]; //初始化标签栏控制器 UITabBarController * pTabBar = [[UITabBarController alloc]init]; //设置标签栏中视图控制器(数组) pTabBar.viewControllers = array; //根据委托协议调用方法 [self goInNemView:pTabBar];}//构造委托协议的方法,把标签控制器放在新的根视图中- (void)goInNemView:(id)sender{ //获取当前程序 UIApplication * app = [UIApplication sharedApplication]; //创建应用程序的委托对象 LinAppDelegate * pDelegate = app.delegate; //设置新的根视图控制器,用委托的方法实现代理 pDelegate.window.rootViewController = sender;}
0 0
- iOS学习笔记——导航栏与标签栏结合
- iOS导航控制器和标签栏控制器的结合
- IOS:标签栏与导航栏
- iOS学习笔记——导航栏(Navigation)
- Ios中导航栏和标签栏的结合以及UIButton、UILabel的使用
- iOS学习笔记-089.彩票04——购彩大厅1_导航栏左边按钮与修改插件
- iOS学习笔记——标签栏(TabBar)
- iOS学习笔记--iOS 11 导航栏透明设置
- iOS开发基础学习笔记——导航控制器2->导航栏(UINavigationBar)/工具栏(toolBar)/导航元素按钮(UINavigationItem)
- iOS开发笔记之三十四——关于导航栏与状态栏的操作总结
- iOS 标签栏和导航栏
- IOS 自定义导航栏和标签栏
- iOS 自定义导航栏笔记
- iOS开发中的导航栏和状态栏学习笔记
- IOS 自定义导航栏 和表格 学习笔记
- 【iOS学习笔记】QQ侧滑导航栏的实现
- iOS学习笔记-048.UINavigationController——导航控制器
- iOS结合导航栏的状态栏字体颜色设置
- java多线程
- Want Speed? Pass by Value.
- TextView使用超链接去掉下划线
- Java 格式化时间 SimpleDateFormat
- 常用正则表达式大全,手机、电话、邮箱、身份证(最严格的验证)、IP地址、网址、日期等,一般前台js验证
- iOS学习笔记——导航栏与标签栏结合
- Python 的VIM 的简单设置
- jQuery Validation Engine 表单验证
- Error: Socket descriptor not found. Hint: the problem might be solved applyi...
- android项目目录说明
- android下MediaPlayer的使用
- Android精美登录界面设计
- android_基础_java回调函数
- 在CentOS下编译最新CUDA5.5例子代码出错解决办法