1、显示Toolbar 

在RootViewController.m的- (void)viewDidLoad方法中添加代码,这样Toobar就显示出来了。

  1. [self.navigationController  setToolbarHidden:NO animated:YES];

2、在ToolBar上添加UIBarButtonItem

新建几个UIBarButtonItem,然后以数组的形式添加到Toolbar中

  1. UIBarButtonItem *one = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
  2. UIBarButtonItem *two = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:nil action:nil];
  3. UIBarButtonItem *three = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];
  4. UIBarButtonItem *four = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:nil action:nil];
  5. UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
  6. [self setToolbarItems:[NSArray arrayWithObjects:flexItem, one, flexItem, two, flexItem, three, flexItem, four, flexItem, nil]];

效果:

注意:用   [self.navigationController.toolbar setItems:(NSArray *) animated:<#(BOOL)#>]这个方法添加item是不起效果的。下面我动态自己添加Toolbar时,这个才起效果。

3、动态添加Toolbar

我们在SecondView添加动态的Toolbar。

在SecondViewController.h添加

  1. #import <UIKit/UIKit.h>
  2. @interface SecondViewController : UIViewController
  3. {
  4. UIToolbar *toolBar;
  5. }
  6. @end

在SecondViewController.m添加

  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4. [self.navigationController  setToolbarHidden:YES animated:YES];
  5. UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(gotoThridView:)];
  6. toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height - toolBar.frame.size.height - 44.0, self.view.frame.size.width, 44.0)];
  7. [toolBar setBarStyle:UIBarStyleDefault];
  8. toolBar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
  9. [toolBar setItems:[NSArray arrayWithObject:addButton]];
  10. [self.view addSubview:toolBar];
  11. // Do any additional setup after loading the view from its nib.
  12. }

先把RootView时显示的Toobar隐藏

[self.navigationController setToolbarHidden:YESanimated:YES];然后把新建的Toolbar添加的SecondView中,并为Toobar设置了一个Item.

[toolBarsetItems:[NSArrayarrayWithObject:addButton]];

BarButtonItem用 的是UIBarButtonSystemItemSearch, 效果如下:

4、新建ThridView,从SecondView跳转到

Commad+N新建一个ThridViewController,

这个addButton跳转到ThridView

  1. -(void)gotoThridView:(id)sender
  2. {
  3. ThridViewController *thridView = [[ThridViewController alloc] init];
  4. [self.navigationController pushViewController:thridView animated:YES];
  5. thridView.title = @"Thrid View";
  6. }

跳转Second到Third效果:

到此UINavigationController练习的差不多了。

前面两篇:

iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

iOS学习之UINavigationController详解与使用()页面切换和segmentedController

例子代码:https://github.com/schelling/YcDemo

著作权声明:本文由http://blog.csdn.net/totogo2010/原创,欢迎转载分享。请尊重作者劳动,转载时保留该声明和作者博客链接,谢谢

iOS学习之UINavigationController详解与使用(三)ToolBar的更多相关文章

  1. [转]iOS学习之UINavigationController详解与使用(三)ToolBar

    转载地址:http://blog.csdn.net/totogo2010/article/details/7682641 iOS学习之UINavigationController详解与使用(二)页面切 ...

  2. iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController

    iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem是上篇,我们接着讲UINavigationController的重要作用,页面的管理和切换. ...

  3. iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

    http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...

  4. [转]iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController

    转载地址:http://blog.csdn.net/totogo2010/article/details/7682433 iOS学习之UINavigationController详解与使用(一)添加U ...

  5. [转]iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

    转载地址:http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINav ...

  6. IOS开发之UINavigationController详解

    UINavigationController是IOS编程中比较常用的一种容器view controller,很多系统的控件(如UIImagePickerViewController)以及很多有名的AP ...

  7. UINavigationController详解一(转)UIBarButtonItem

    本文出自:http://www.cnblogs.com/smileEvday/archive/2012/05/14/2495153.html 特别感谢. 1.UINavigationControlle ...

  8. IOS 友盟使用详解

    IOS 友盟使用详解 这篇博客将会详细介绍友盟的使用,希望对博友们有所帮助. 首先我们在浏览器上搜索友盟. 在这里我们选择官网这个,进去友盟官网后我们按照下图进行选择. 接下来选择如下图 Next 这 ...

  9. iOS中—触摸事件详解及使用

    iOS中--触摸事件详解及使用 (一)初识 要想学好触摸事件,这第一部分的基础理论是必须要学会的,希望大家可以耐心看完. 1.基本概念: 触摸事件 是iOS事件中的一种事件类型,在iOS中按照事件划分 ...

随机推荐

  1. lua不支持的泛型方法

    1.没有泛型约束 2.缺少带约束的泛型参数 3.泛型约束必须为class /// <summary> /// 不支持生成lua的泛型方法(没有泛型约束) /// </summary& ...

  2. 搭建jetbrains 注册服务器

    wget http://home.ustc.edu.cn/~mmmwhy/jetbrain.sh && sh ./jetbrain.sh 输入默认的端口号跟用户名,然后记住服务器地址. ...

  3. 关于simulink hdlcoder的优化问题

    HDL Block Properties中包含有多个优化选项. 1,delay balance 当其他分支优化过后,可能会引入一个或几个周期的delay,这时候需要在与其并行的几条信号路径上也加上de ...

  4. Kanboard 看板工具配置使用

    备注:     类似的开源工具有wekan 界面还有功能和Trello 类似.比较方便   1. 安装(基于docker+ docker-compose) a. 安装docker && ...

  5. Java 设计模式之工厂模式(二)

    原文地址:Java 设计模式之工厂模式(二) 博客地址:http://www.extlight.com 一.背景 本篇内容是 Java 设计模式创建型模式的第二篇.上一篇主题为 <Java 设计 ...

  6. PHP远程连接mysql

    http://blog.chinaunix.net/uid-23215128-id-2951624.html # mysql -urootmysql> use mysql; Database c ...

  7. Unit05: 实战技巧 、 资费列表 、 拦截器

    Unit05: 过滤器解决表单写中文乱码.拦截器 1. 使用过滤器解决表单中文参数值乱码问题 注意: a. 表单提交方式必须为POST. b. 过滤器的编码应该与浏览器端设置的编码一致. 2. 拦截器 ...

  8. Windows Driver Kit Version 7.1.0 ( 也就是 7600.16385.1 ) 下载地址

    Windows Driver Kit Version 7.1.0 ( 也就是 7600.16385.1 ) 下载地址 http://download.microsoft.com/download/4/ ...

  9. JVM内存管理之JAVA语言的内存管理概述

    引言 内存管理一直是JAVA语言自豪与骄傲的资本,它让JAVA程序员基本上可以彻底忽略与内存管理相关的细节,只专注于业务逻辑.不过世界上不存在十全十美的好事,在带来了便利的同时,也因此引入了很多令人抓 ...

  10. MySQL的Query Cache原理分析

    QueryCache(下面简称QC)是根据SQL语句来cache的.一个SQL查询如果以select开头,那么MySQL服务器将尝试对其使用QC.每个Cache都是以SQL文本作为key来存的. 原理 ...