`
sinye
  • 浏览: 217611 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

iOS UINavigationController与UITabBarController的组合使用

    博客分类:
  • iOS
阅读更多

1.导航类型

UINavigationController 适用于父子页面的跳转

UITabBarController 适用于平级页面的跳转

 

2.presentViewController / dismissViewControllerAnimated和pushViewController / popViewController

(1)只有从UINavigationController导航过来的UIViewController 才可以使用pushViewController / popViewController,从其它导航进入的只能使用presentViewController / dismissViewControllerAnimated

(2)如果A界面是通过presentViewController进入的,那么在A界面里只能使用presentViewController导航,如果A界面是通过UINavigationController包装了一层进入,则可使用pushViewController导航。

(3)如果A界面是一个UITabBarController,进入时是通过presentViewController来导航的,那么子Tab里也只能通过presentViewController来导航,如果进入时是通过UINavigationController包装了一层进入,则可使用[self.tabBarController.navigationController pushViewController:abcdViewController animated:true];这种方式导航。

 

3.修改UINavigationController导航进入后导航栏的图标及文字

UIBarButtonItem* leftBar = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(homeBack)];

self.navigationItem.leftBarButtonItem = leftBar;

//可添加多个导航按钮

 

//    self.navigationItem.leftBarButtonItems = nil;

//同样右边的导航按钮也可以设置

 

4.创建UITabBarController时需注意,要先创建出来,然后通过UINavigationController包装后才能显示,否则tab子项不显示。创建格式如下

TabOneViewController* oneVC = [[TabOneViewController alloc]init];
    oneVC.view.backgroundColor = [UIColor whiteColor];
    UITabBarItem* item1 = [[UITabBarItem alloc]initWithTitle:@"tab1" image:nil tag:0];
    oneVC.tabBarItem = item1;
    
    TabTwoViewController* twoVC = [[TabTwoViewController alloc]init];
    UITabBarItem* item2 = [[UITabBarItem alloc]initWithTitle:@"tab2" image:nil tag:1];
    twoVC.tabBarItem = item2;

    HomeViewController* homeVC = [[HomeViewController alloc]init];
    NSArray* array = [[NSArray alloc]initWithObjects:oneVC,twoVC, nil];
    homeVC.viewControllers = array;
    
    UINavigationController* navVC = [[UINavigationController alloc]initWithRootViewController:homeVC];
    [self presentViewController:navVC animated:YES completion:^{}];
    
    //下面这种创建了HomeViewController后,HomeViewController下的子Tab不能通过push或者pop导航
    //    HomeViewController* homeVC = [[HomeViewController alloc]init];
    //    [self presentViewController:homeVC animated:YES completion:^{}];

 

 

5.UITabBarController各页面之间的切换

实现UITabBarControllerDelegate协议

//实现协议方法,用于切换Tab时,更改页面的标题
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSInteger index = tabBarController.selectedIndex;
    NSString *title;
    switch (index) {
        case 0:
            title = @"Message";
            break;
        case 1:
            title = @"User List";
            break;
    }
    self.title 

参考文章:http://www.tuicool.com/articles/J7nIVbN

 

 

1
0
分享到:
评论

相关推荐

    iOS 自定义UINavigationController和UITabBarController

    iOS 自定义UINavigationController和UITabBarController

    UINavigationController+UITabBarController框架

    我们写iOS项目的时候,基本都是一个UINavigationController套一个UITabBarController的形式,就是上面一个导航栏,下面几个按钮的工具条的形式。我写了几个应用,发现如果每次都重新写的话完全就是浪费精力和时间,...

    iOS开发例程 -- UINavigationController和UITabBarController合用

    很多时候我们创建一个基于UITabBarController的application以后还希望能够在每个tab view都可以实现导航控制,即添加一个UINavigationController来实现tabview内部的view之间的切换,这即是本文所要介绍的。

    UITabBarController和UINavigationController的整合使用

    UITabBarController和UINavigationController的整合使用DEMO,详情见:http://blog.csdn.net/hwe_xc/article/details/50588500

    纯代码搭建iOS三级结构(UITabbarController+UINavigationController+UIViewController)

    详情请看博客http://blog.csdn.net/ecjtuacm_yuewei/article/details/69400245

    显示iOS所有可用字体以及颜色

    使用UINavigationController、UITabBarController、UITableViewController、UISearchDisplayController搭建的程序框架

    iOS应用开发中UITabBarController标签栏控制器使用进阶

    做了这么长时间的ios开发了,最基本的UITabBarController和UINavigationController都用了好长时间了,总是改现成的代码,或者各种自定义控件的修改,用的都有些混乱了,呵呵。还是自己做个demo再复习一下吧,记录...

    iOS的UI开发中UITabBarControlle的基本使用教程

    UITabBarController和UINavigationController类似,UITabBarController也可以轻松地管理多个控制器,轻松完成控制器之间的切换,典型的例子就是QQ、微信等应⽤。 二、UITabBarController的使用 1.使用步骤: (1)...

    iOS 项目框架的搭建

    iOS 项目框架的搭建包括UIPageControl,UIScrollView,自定义UINavigationController,自定义UITabBarController,打开项目即可使用

    iOS实现容器视图控制器的方法

    (类似于系统的UINavigationController以及UITabbarController); 比如下面几个方法就是MMDrawerController实现的: 下面的描述是官方文档帮助理解什么是容器控制器,文档中以UINavigationController和...

    MZNavTab:MZNavTab 是一个 iOS 库,它可以帮助你结合 UITabBar 和 UINavigationController

    作为 iOS 开发者,您可能知道在您的应用程序中组合 UITabBarController 和 UINavigationController 会复杂得多,主要是我们希望在导航控制器中推送或弹出时控制标签栏的可见性。如何运行示例克隆存储库git@github....

    iOS屏幕旋转与锁屏的示例代码

    在做视频开发时遇到屏幕旋转问题,其中涉及到 StatusBar、 UINavigationController、UITabBarController 、UIViewcontroller 。 在设备锁屏下的整体效果图 iOS-旋转.gif 主要涉及以下4点: 横竖屏的旋转 屏幕旋转...

    iOS开发中导航控制器的基本使用教程

    多控制器和导航控制器简单介绍 一、多控制器 一个iOS的app很少只由一个控制器组成,除非这个app极其简单。当app中有多个控制器的时候,我们就需要对... UINavigationController UITabBarController 二、导航控制器 利用

    iOS SDK Programming A Beginners Guide

    9 UINavigationBar and UINavigationController 10 Tables Using UITableView and UITableViewController 11 Activity Progress and Alerting Users 12 Controls—Part One: Using Buttons, Sliders, Switches, ...

    TransitionController::party_popper:

    您可以关闭UIViewController,UINavigationController,UITabBarController,UICollectionViewController和UITableViewController之间的过渡并显示当前过渡。 接收ViewController的willPresent,didPresent,...

    ios-dev-resources:IOS应用开发的知识和资源

    ios-dev-resources说明:IOS 开发知识及资源沉淀。一. IOS应用开发知识体系二. 常用工具xcode三. 编程语言Swift四. 常用框架1. UIKit注:从 IOS 7.0 开始被废弃的类,不会整理在这里。 -- 按钮 -- 滑块 -- 切换 -- ...

    ios源码 音乐台

    最近比较无聊,就自己做了一个音乐台的应用,也是在练习UITabBarController和UINavigationController的集合使用 以及表格和持久化, 如果要听歌的话 要确保电脑连上网。 下载查看都 希望给予评论 有什么不足的地方还...

    导航控制器

    UINavigationController是构建分层应用的主要工具,他与UITabBarController很类似.但是UINavigationController是以栈(stack)来实现功能,关于栈,遵循先进后出的原则,向栈中添加一个对象为入栈(push),从栈中删除一个...

    IOS5 Programming Cookbook

    2.12 Presenting Multiple View Controllers with UITabBarController 182 2.13 Displaying Static Text with UILabel 191 2.14 Accepting User Text Input with UITextField 196 2.15 Displaying Long Lines of ...

Global site tag (gtag.js) - Google Analytics