UINavigationController又被成为导航控制器,继承自UIViewController,以栈的方式管理所控制的视图控制器,下面就详细说一下UINavigationController的使用:

1、首先新建一个工程(就不多说了)创建RootViewController(继承自UIViewController)。

2、打开AppDelegate.h文件添加属性

3、打开AppDelegate.m文件的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法添加navController和根视图(RootViewController)。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *rootVC = [[RootViewController alloc] init];
rootVC.title = @"RootViewController"; //初始化navController
self.navController = [[UINavigationController alloc] init];
//给rootVC添加推入动作
[self.navController pushViewController:rootVC animated:YES];
//将navController加到window上
[self.window addSubview:self.navController.view]; [self.window makeKeyAndVisible]; return YES;
}

效果图:

4、添加UIBarButtonItem

注:UIBarButtonItem分为leftBarButtonItem和rightBarButtonItem;

 #import "RootViewController.h"

 @interface RootViewController (){

     UIBarButtonItem *leftButton;
UIBarButtonItem *rightButton; } @end @implementation RootViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib. leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(leftButtonAction:)];
self.navigationItem.leftBarButtonItem = leftButton; rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(rightButtonAction:)];
self.navigationItem.rightBarButtonItem = rightButton; }

效果图:

这里还要说一下initWithBarButtonSystemItem:即系统自带按钮风格:

UIBarButtonSystemItemDone:蓝色文字按钮,标有“Done”;

UIBarButtonSystemItemCancel:文字按钮,标有“Cancel”;

UIBarButtonSystemItemEdit:文字按钮,标有“Edit”;

UIBarButtonSystemItemSave:蓝色文字按钮,标有“Save”;

UIBarButtonSystemItemAdd:图像按钮,上面有一个Å符号;

UIBarButtonSystemItemFlexibleSpace:空白,占用空间大小可变;

UIBarButtonSystemItemFixedSpace:空白占位符;

UIBarButtonSystemItemCompose:图像按钮,上有一支笔和纸张;

UIBarButtonSystemItemReply:图像按钮,上有一个回复箭头;

UIBarButtonSystemItemAction:图像按钮,上有一个动作箭头;

UIBarButtonSystemItemOrganize:图像按钮,上有一个文件夹以及向下箭头;

UIBarButtonSystemItemBookmarks:图像按钮,上有书签图标;

UIBarButtonSystemItemSearch:图像按钮,上有spotlight图标;

UIBarButtonSystemItemRefresh:图像按钮,上有一个环形的刷新箭头;

UIBarButtonSystemItemStop:图像按钮,上有一个停止记号X;

UIBarButtonSystemItemCamera:图像按钮,上有一个照相机;

UIBarButtonSystemItemTrash:图像按钮,上有一个垃圾桶;

UIBarButtonSystemItemPlay:图像按钮,上有一个播放图标;

UIBarButtonSystemItemPause:图像按钮,上有一个暂停图标;

UIBarButtonSystemItemRewind:图像按钮,上有一个倒带图标;

UIBarButtonSystemItemFastForward:图像按钮,上有一个快进图标;

5、UIBarButtonItem的事件的实现

 - (void)leftButtonAction:(UIBarButtonItem*)leftAction{

     UIAlertView *leftAlert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"是否继续编辑" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
[leftAlert show];
} - (void)rightButtonAction:(UIBarButtonItem*)rightAction{ UIAlertView *rightAlert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"退出" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
[rightAlert show]; }

效果图:

ios基础篇(十)——UINavgationController的使用(一)UIBarButtonItem的添加的更多相关文章

  1. ios基础篇(十二)——UINavgationController的使用(三)ToolBar

    UIToolBar存在于UINavigationController导航栏控制器中,而且默认被隐藏:设置UINavigationController的toolbarHidden属性可显示UIToolB ...

  2. ios基础篇(十六)——UIWebView的基本使用

    UIWebView是内置的浏览器控件,可以用它来浏览网页.打开文档等.UIWebView是一个混合体,具体的功能控件内置的,实现一些基本的功能.UIWebView可以查看Html网页,pdf文件,do ...

  3. ios基础篇(二十六)—— UITableViewCell的分组索引与标记

    一.表视图的索引目录 首先要创建一个TableView,之前有说过,这里就不详细说了(参考前面第十四篇). 直接贴代码吧, #import "ViewController.h" @ ...

  4. ios基础篇(二十九)—— 多线程(Thread、Cocoa operations和GCD)

    一.进程与线程 1.进程 进程是指在系统中正在运行的一个应用程序,每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内: 如果我们把CPU比作一个工厂,那么进程就好比工厂的车间,一个工厂有 ...

  5. ios基础篇(二十五)—— Animation动画(UIView、CoreAnimation)

    Animation主要分为两类: 1.UIView属性动画 2.CoreAnimation动画 一.UIView属性动画 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程.UIVie ...

  6. ios基础篇(二十四)—— 文字、图片的绘制及其自定义Button

    这篇文章我们主要来拿官方的控件来研究一下,我们来仿照官方的控件,自己来实现它提供的控件: 首先来看看基本的图片与文字的绘制,很简单. 一.imageView 所有的视图都是继承自UIView,所以我们 ...

  7. ioS基础篇(十九)——UIResponder简析

    UIResponder类定义了对象相应和控制事件的接口,他是UIApplication.UIView的超类,这类的实例通常被称为应答对象. 一.Responder对象 在iOS系统中,能够响应并处理事 ...

  8. ios基础篇(十八)——Delegate 、NSNotification 和 KVO用法及其区别

    一.Delegate Delegate本质是一种程序设计模型,iOS中使用Delegate主要用于两个页面之间的数据传递.iphone中常用@protocol和delegate的机制来实现接口的功能. ...

  9. iOS基础篇(十五)——UIScrollView的基本用法

    滚动视图(UIScrollView)通常用于显示内容尺寸大于屏幕尺寸的视图. 一.基本属性 1.CGSize contentSize :设置UIScrollView的滚动范围 2.CGPoint co ...

随机推荐

  1. Servlet&jsp基础:第五部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. NSKeyedArchive(存储自定义对象)

    在viewController.m中: - (void)viewDidLoad { [super viewDidLoad]; ZWPerson *p = [[ZWPerson alloc] init] ...

  3. poj 1106 Transmitters (叉乘的应用)

    http://poj.org/problem?id=1106 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4488   A ...

  4. hdu 1086(计算几何入门题——计算线段交点个数)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2 ...

  5. redis系列

    1.redis windows下的环境搭建 2.redis初学系列

  6. iOS - OC NSProcessInfo 系统进程信息

    前言 @interface NSProcessInfo : NSObject NSProcessInfo 类中包含一些方法,允许你设置或检索正在运行的应用程序(即进程)的各种类型的信息. 1.获取系统 ...

  7. oracle dba 职责, 及个人需要掌握内容

    ORACLE DBA 职责, 基本相当于日常工作. 0. 数据库设计 1. 模式对象的创建与管理(table, index 等等) 2. 事物管理, 例如并发等 3. SQL 调优 只是针对SQL的 ...

  8. NullPointerException异常的原因??

    所谓空指针异常,是因为用空(null)去调用属性或方法.   null表示没有这个对象,既然没有这个对象,那么去调用他的属性和方法,就会报异常.   <--主要有以下几种原因:   1.使用了未 ...

  9. java技术知识点

    1   自我介绍 2  做过的项目 (Java 基础) 3  Java的四个基本特性(抽象.封装.继承,多态),对多态的理解(多态的实现方式)以及在项目中那些地方用到多态 Java的四个基本特性 ◦  ...

  10. 在map中根据value获取key

    原文:http://blog.csdn.net/mexican_jacky/article/details/51789548 //根据map的value获取map的key private static ...