掌握:

  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. url长度

    今天在测试Email Ticket的时候发现在进行Mark as Read/Unread操作时,请求是通过GET方式进行的.URL中列出了所有参与该操作的Ticket Id.于是,我想起GET请求是有 ...

  2. baidu-aip-SDK node.js 身份证识别

    最近项目中客户需要实现身份证识别功能,合理计划了之后决定使用百度ai的身份证识别. 身份证识别是文字识别的一种,类似的功能有很多比如驾驶证识别等等,原理都是相同的. 对于前端初学者来说,如果要实现这种 ...

  3. 手把手教你用android studio创建第一个安卓程序加载html5页面(二)

    经过上一篇,我们已经可以打开html页面了,但是有很多细节方面的内容我们还需要调整. 打开链接的问题 细心的网友可能已经发现,打开百度页面后,点击顶部的链接,会在手机的浏览器中打开相应的页面,这显然不 ...

  4. WebAPI示例

    一.新建项目 二. 代码: Models.Products实体类 public class Product { /// <summary> /// 产品编号 /// </summar ...

  5. 炫酷的Html+css (一)

    博客园在别的 博主看到一个样式, 里面有一段这样的 正方体旋转的 动态图 吸引了我. 找博主要了代码, 贴出来 与大家共享. 鼠标放上去会展开 一大一小两个正方体, 鼠标悬浮上去, 外面的正方体会展开 ...

  6. Laravel Scheduling Package

    Laravel 是在 App\Console\Kernel 类中的 schedule 方法去定义所有的调度任务. iBrand 产品作为一个电商类产品,本身业务需求非常庞大和复杂,全部定义在 sche ...

  7. JavaScript 面向对象编程(二):继承

    Javascript面向对象编程(二):构造函数的继承 这个系列的第一部分,主要介绍了如何"封装"数据和方法,以及如何从原型对象生成实例. 今天要介绍的是,对象之间的"继 ...

  8. Linux远程桌面(二)

    上一篇远程桌面采用的独立服务配置不适用于过多用户,这一篇采用超级Internet服务器搭建vnc服务可以解决多用户问题.  vnc之xinetd服务搭建配置 Linux远程桌面(一):vnc之独立服务 ...

  9. ffmpeg控制台上不能输出信息的解决办法

    最近遇到下面类似的问题 我下载了最新版本(1.1.2)版本的ffmpeg,在windows平台下使用msys+mingw编译成功后,我输入命令后,一点输出信息都没有,例如: ffmpeg -v 这时候 ...

  10. jade在命令行实时编译

    jade文件: doctype html html head title jade study body h1 imoock jade study 在jade文件夹下,终端输入 jade index. ...