转载地址:http://blog.csdn.net/totogo2010/article/details/7682641

iOS学习之UINavigationController详解与使用()页面切换和segmentedController 接上篇,我们接着讲Navigation 的Toolbar。

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详解与使用(三)ToolBar的更多相关文章

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

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

  2. iOS学习之UINavigationController详解与使用(三)ToolBar

    1.显示Toolbar  在RootViewController.m的- (void)viewDidLoad方法中添加代码,这样Toobar就显示出来了. [cpp] view plaincopy [ ...

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

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

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

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

  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. [转]iOS学习笔记(2)--Xcode6.1创建仅xib文件无storyboard的hello world应用

    转载地址:http://www.mamicode.com/info-detail-514151.html 由于Xcode6之后,默认创建storyboard而非xib文件,而作为初学,了解xib的加载 ...

  8. UINavigationController详解一(转)UIBarButtonItem

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

  9. IOS 友盟使用详解

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

随机推荐

  1. js 页码分页的前端写法

    <script type="text/javascript"> var curPage = 1;//当前页码 var total;//总页数 $(function () ...

  2. 示例在同一台机器上使用RMAN克隆数据库

    1.查看主库ZDJS并使用RMAM进行备份 [oracle@std ~]$ sqlplus '/as sysdba' SQL*Plus: Release - Production on Wed Jan ...

  3. centos6 系统优化脚本

    #!/bin/bash # 检查是否为root用户,脚本必须在root权限下运行 # if [[ "$(whoami)" != "root" ]]; then ...

  4. Python 基础 - 随机列表最大的两个值

    # -*- coding: utf-8 -*- #author:v def sywmemeda(l): #list 冒泡排序 length = len(l) for i in range(length ...

  5. php初学第一课

    php:强大的脚本语言 B/S:brower:浏览器 server:服务器 C/S: client:客户端 server:服务器 一.php嵌入页面的标记 1. <?php    ?> # ...

  6. jquery 同id使用指针寻找具体每个id的值

    this来判断<script language="javascript"> function t(obj) { alert(obj.value); } </scr ...

  7. Python强化训练笔记(三)——词频的统计

    现有列表如下: [6, 7, 5, 9, 4, 1, 8, 6, 2, 9] 希望统计各个元素出现的次数,可以看作一个词频统计的问题. 我们希望最终得到一个这样的结果:{6:2, 7:1...}即 { ...

  8. 3D Touch

    一.认识3D Touch   1.硬件和操作系统要求      iPhone 6s或者iPhone 6s Plus      操作系统要求 ios9+ 2.3D Touch的交互效果 QuickAct ...

  9. win7下用mklink命令解决delphiXE系列占用C盘空间的问题

    DelphiXE从2010以后, 安装程序安装完成后都会在ProgramData目录里复制一份安装程序的备份, 随着版本升级安装包越来越大, 占用C盘的空间也就越来越大 虽然可以通过删除的方式删掉, ...

  10. [PCL]FPFH描述子

    fpfh_est.setSearchSurface(data); 如果没有设置SearchSurface,使用input数据集作为查找的表面 // If no search surface has b ...