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. [SAP ABAP开发技术总结]ABAP读写、解析XML文件

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

  2. x名称空间

    XAML代码的WPF程序都需要通过语句:xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml",x就是用来映射xmlns:x= ...

  3. Python基础学习笔记(一)入门

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-chinese-encoding.html 3. http://w ...

  4. CSS笔记(一)CSS规则

    CSS是层叠式样式表(Cascading Style Sheets)的缩写,定义了如何显示HTML元素. CSS规则由两个主要的部分构成:选择器 + 一条或多条声明. 每条声明由一个属性和一个值构成. ...

  5. Memcached通用类(基于Memcached Client Library)

    分享下自己编写的Memcached通用类.欢迎大家帮忙指点下哈~ 使用的是.NET memcached client library 客户端+Memcached Providers using Sys ...

  6. Flex打印功能FlexPrintJob调用

    收藏下很详细的学习资料 http://wenku.baidu.com/view/b3d4f40702020740be1e9bf8.html import mx.printing.FlexPrintJo ...

  7. ZOJ-3725 Painting Storages 动态规划

    题意:给定一个数N,表示有N个位置,要么放置0,要么放置1,问至少存在一个连续的M个1的放置方式有多少? 分析:正面求解可能还要考虑到重复计算带来的影响,该题适应反面求解.设dp[i][j]表示到前 ...

  8. [转载] what's goole mock

    原文: https://code.google.com/p/googlemock/wiki/V1_7_ForDummies 地址被墙了, 看起来费劲, 转载一份 Google C++ Mocking ...

  9. css+js实现兼容性select的样式

    <!doctype html><html lang="en"> <head> <meta charset="UTF-8" ...

  10. Hbase之尝试使用错误列族获取数据

    import com.google.common.base.Strings; import org.apache.hadoop.conf.Configuration; import org.apach ...