掌握:

  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. table表格td内内容自动换行

    项目开发时,遇到问题:td内传入数据,全是字母,不会自动换行 一般字母数字/特殊符号的话,会被浏览器默认是一个字符串或者说一个单词,不会自动换行 所以需要设置一下,让表格内容自动换行. 1.给td标签 ...

  2. Struts2 displaytag 导出文件为空

    以一个user的查询为例,在struts.xml配置里有这个action的配置: 然后可以在UserAction.java里找到list方法这个就是无非new 一个List<User> u ...

  3. C#保存图片到数据库并读取显示图片的方法

    private void button2_Click_1(object sender, System.EventArgs e) { string pathName; if (this.openFile ...

  4. LDAP 在ubuntu14.04下的安装配置install and configure

    https://help.ubuntu.com/lts/serverguide/openldap-server.html if error occurs in reinstall, try this: ...

  5. 国外统计学课程主页Statistical Books, Manuals and Journals

    国外统计学课程主页Statistical Books, Manuals and Journalshttp://statpages.info/javasta3.html

  6. centos命令行常用操作

    1.查看某个端口占用 lsof -i tcp:80 2.查看是否安装了防火墙 service iptables status 查看是否启用防火墙/etc/init.d/iptables status ...

  7. 笨办法学Python(九)

    习题 9: 打印,打印,打印 # Here's some new strange stuff, remember type it exactly. days = "Mon Tue Wed T ...

  8. TP5.1:模板继承(重要知识点)

    1.在app\index\controller文件夹新建一个名为Lyot(自定义)的控制器,在控制器中定义: 2.创建一个被继承的public(自定义)文件夹,里面有三个文件,分别是header.ht ...

  9. POJ-3614 Sunscreen---贪心+优先队列

    题目链接: https://vjudge.net/problem/POJ-3614 题目大意: 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小 ...

  10. 种类并查集,TOJ(1706)

    题目链接:http://acm.tju.edu.cn/toj/showp1706.html 很类似Poj的一道帮派的问题,记得找到的可疑的关系,不要将集合刷新就可以了. 1706.   A Bug's ...