掌握:

  1. UINavigationController的使用:添加、移除控制器。

  2. UINavigationBar内容的设置。

---------------------------------------------------------------------------------------------------------

一、控制器的添加和移除:

  1. UINavigationController以栈的形式保存子控制器:

    @property(nonatomic,copy) NSArray *viewControllers;

    @property(nonatomic,readonly) NSArray *childViewControllers;

2. 使用push方法能将某个控制器压入栈

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;

/** 下面方法中用作示意*/

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
          self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
          self.window.backgroundColor = [UIColor whiteColor];
    
      // 1.创建导航控制器
            XZOneViewController *one = [[XZOneViewController alloc] init];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:one]; // 传入一个栈底控制器来初始化导航控制器 (常用)

  
      //  拿到栈顶控制器(显示在眼前的控制器)
      //  nav.topViewController

//  存放所有子控制器的栈
      //  nav.viewControllers
      //  这个数组也存放子控制器
      //  nav.childViewControllers

//  2.添加子控制器
      //  XZOneViewController *one = [[XZOneViewController alloc] init];
      //  [nav addChildViewController:one];                // 这样子也能把one控制器放到 数组 viewControllers 和  childViewControllers 中。
      //  [nav pushViewController:one animated:YES]; // 将one压入栈中,即放入 viewControllers 和 childViewControllers 中。 (推荐用法,有动画)

//  nav.viewControllers = @[one];  // 这样也是设置
      //  nav.viewControllers = @[one];  // 不能这么干,因为viewControllers是只读的。

// 3.设置为窗口的根控制器
          self.window.rootViewController = nav;
    
          [self.window makeKeyAndVisible];
          return YES;
}

3. 使用pop方法可以移除控制器
  // 将栈顶的控制器移除

  - (UIViewController *)popViewControllerAnimated:(BOOL)animated;

  // 回到指定的子控制器

  - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;

  // 回到根控制器(栈底控制器)

  - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;

 
  4. 导航栏的内容由栈顶控制器的navigationItem属性决定
 
    UINavigationItem有以下属性影响着导航栏的内容
    // 左上角的返回按钮

      @property(nonatomic,retain) UIBarButtonItem *backBarButtonItem;

 
    // 中间的标题视图

      @property(nonatomic,retain) UIView          *titleView;

    
    // 中间的标题文字

      @property(nonatomic,copy)   NSString        *title;

    
      // 左上角的视图

      @property(nonatomic,retain) UIBarButtonItem *leftBarButtonItem;

    // 右上角的视图

      @property(nonatomic,retain) UIBarButtonItem *rightBarButtonItem;

二、控制器的view结构 以及 UINavigationBar导航条内容的设置:

  1. 情景一:

  self.navigationItem.title = @"第一个控制器";
   
      UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:nil action:nil];   
      UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:nil action:nil];
    
      self.navigationItem.rightBarButtonItems = @[item1, item2];
      self.navigationItem.leftBarButtonItems   = @[item1, item2];

  

  2. 情景二:

      self.navigationItem.titleView = [UIButton buttonWithType:UIButtonTypeContactAdd];
      self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:nil action:nil];

UINavigationController相关的更多相关文章

  1. 系统UINavigationController使用相关参考

    闲来无事便在网上google&baidu了一番UINavigationController的相关文章,然后又看了下官方文档:看看更新到iOS7之后UINavigationController的 ...

  2. 嵌入式单片机STM32应用技术(课本)

    目录SAIU R20 1 6 第1页第1 章. 初识STM32..................................................................... ...

  3. UINavigationController与UITabBarController相关问题

    UINavigationController与UITabBarController相关问题 UINavigationController与UITabBarController混用是非常常见的,有时候会 ...

  4. UINavigationController的创建和相关设置---学习笔记四

    导航控制器 一.设置字体大小,背景等. 二.自定义返回按钮. 三.设置手势. 一.导航中也有个appearance属性,通过它可以设置所有导航的颜色. 二.自定义返回按钮. 1.首先需要知道的是,要把 ...

  5. IOS UINavigationController 操作相关集合

    1.修改中间Title字体以及大小 [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dict ...

  6. UINavigationController

    知识点: 1)UINavigationController 2)UINavigationBar 3)UINavigationItem 4)UIToolBar ===================== ...

  7. UIScrollerView遇到UINavigationController

    今天在UITabBarController  的第一个Tab 页面中放入一个ScrollView, 原本以为可以正常运行. 结果却让人大跌眼镜.  每当我手动滚动或者 缓慢导航到另外一个页面时,当前的 ...

  8. 升级到iOS9之后的相关适配

    iOS9AdaptationTips(iOS9开发学习交流群:458884057) iOS9适配系列教程[中文在页面下方]转自@iOS程序犭袁 (截至2015年9月26日共有10篇,后续还将持续更新. ...

  9. iOS开发UINavigation——导航控制器UINavigationController

    iOS开发UINavigation系列一——导航栏UINavigtionBar摘要iOS中的导航条可以附着于导航控制器之中使用,也可以在controller中单独使用,这篇博客,主要讨论有关导航栏的使 ...

随机推荐

  1. Vue.js基础语法(一)

    vue学习的一系列,全部来自于表哥---表严肃,是我遇到过的讲课最通透,英文发音最好听的老师,想一起听课就去这里吧 https://biaoyansu.com/i/hzhj1206 前言: 前端解析数 ...

  2. Spring-cloud学习线路

    学习本学习路线学习完,大家将会对微服务.Spring Cloud.Docker.Kubernetes有一个系统.全面的认识.通过学习,将能掌握相关的知识体系,并能够投入到项目实战中去. 本学习路线采用 ...

  3. maven课程 项目管理利器-maven 1-2maven介绍和环境搭建

    maven简介: Maven是基于项目对象模型(POM),通过一小段描述信息来管理项目的构建.报告和文档的软件项目管理工具. 1.1 Maven安装文件夹的结构 bin 目录放置包含mvn的运行脚本 ...

  4. (生产)vuex - 状态管理

    参考:https://vuex.vuejs.org/zh-cn/ 安装 直接下载 / CDN 引用 https://unpkg.com/vuex在 Vue 之后引入 vuex 会进行自动安装:< ...

  5. vue2.0高仿饿了么better-scroll

    首先安装better-scroll npm i better-scroll -S goods页面模板 <template> <div class="goods"& ...

  6. RESTful API设计基本原则

    REST四个基本原则:1.使用HTTP动词:GET POST PUT DELETE:2.无状态连接,服务器端不应保存过多上下文状态,即每个请求都是独立的:3.为每个资源设置URI:4.通过XML JS ...

  7. <Android 基础(九)> Ndk配置与Demo

    介绍 The NDK is a toolset that allows you to implement parts of your app using native-code languages s ...

  8. python模块详解 time与date time

    模块的分类: a:标准库 内置模块 如sys,os等 b:开源模块 大神封装好的 直接可以拿来用的. c:自定义模块 自己封装的模块 Python中通常表示时间的方式有:时间戳.格式化的日期.元组(九 ...

  9. appium(二)简单的demo

     转自http://blog.csdn.net/Yejianyun1/article/details/55517418     启动appium服务,连接手机,将测试用例demo存放到.py文件中 # ...

  10. megacli使用

    查看raid类型 /opt/RAID/MegaCli64 -ShowSummary -a0 System Operating System: Linux version 2.6.32-220.el6. ...