ios基础篇(十)——UINavgationController的使用(一)UIBarButtonItem的添加
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的添加的更多相关文章
- ios基础篇(十二)——UINavgationController的使用(三)ToolBar
UIToolBar存在于UINavigationController导航栏控制器中,而且默认被隐藏:设置UINavigationController的toolbarHidden属性可显示UIToolB ...
- ios基础篇(十六)——UIWebView的基本使用
UIWebView是内置的浏览器控件,可以用它来浏览网页.打开文档等.UIWebView是一个混合体,具体的功能控件内置的,实现一些基本的功能.UIWebView可以查看Html网页,pdf文件,do ...
- ios基础篇(二十六)—— UITableViewCell的分组索引与标记
一.表视图的索引目录 首先要创建一个TableView,之前有说过,这里就不详细说了(参考前面第十四篇). 直接贴代码吧, #import "ViewController.h" @ ...
- ios基础篇(二十九)—— 多线程(Thread、Cocoa operations和GCD)
一.进程与线程 1.进程 进程是指在系统中正在运行的一个应用程序,每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内: 如果我们把CPU比作一个工厂,那么进程就好比工厂的车间,一个工厂有 ...
- ios基础篇(二十五)—— Animation动画(UIView、CoreAnimation)
Animation主要分为两类: 1.UIView属性动画 2.CoreAnimation动画 一.UIView属性动画 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程.UIVie ...
- ios基础篇(二十四)—— 文字、图片的绘制及其自定义Button
这篇文章我们主要来拿官方的控件来研究一下,我们来仿照官方的控件,自己来实现它提供的控件: 首先来看看基本的图片与文字的绘制,很简单. 一.imageView 所有的视图都是继承自UIView,所以我们 ...
- ioS基础篇(十九)——UIResponder简析
UIResponder类定义了对象相应和控制事件的接口,他是UIApplication.UIView的超类,这类的实例通常被称为应答对象. 一.Responder对象 在iOS系统中,能够响应并处理事 ...
- ios基础篇(十八)——Delegate 、NSNotification 和 KVO用法及其区别
一.Delegate Delegate本质是一种程序设计模型,iOS中使用Delegate主要用于两个页面之间的数据传递.iphone中常用@protocol和delegate的机制来实现接口的功能. ...
- iOS基础篇(十五)——UIScrollView的基本用法
滚动视图(UIScrollView)通常用于显示内容尺寸大于屏幕尺寸的视图. 一.基本属性 1.CGSize contentSize :设置UIScrollView的滚动范围 2.CGPoint co ...
随机推荐
- [SAP ABAP开发技术总结]业务对象和BAPI
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- FJNU 1159 Fat Brother’s new way(胖哥的新姿势)
FJNU 1159 Fat Brother’s new way(胖哥的新姿势) Time Limit: 1000MS Memory Limit: 257792K [Description] [题目 ...
- POJ 3617 Best Cow Line(最佳奶牛队伍)
POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...
- iOS - OC 与 Swift 互相操作
前言 在 Swift 语言中,我们可以使用 Objective-C.C 语言编写代码,我们可以导入任意用 Objective-C 写的 Cocoa 平台框架.Objective-C 框架或 C 类库. ...
- [转载] 多年积累的 mysql 运维经验
原文: http://mp.weixin.qq.com/s?__biz=MzA3MzYwNjQ3NA==&mid=207132223&idx=1&sn=f5d98146f282 ...
- windos多线程编程
随机数滚动发生器 #include <stdio.h> #include <Windows.h> #include <ctime> #include <pro ...
- HTML5探索之datalist研究
最近一个项目需要用到类似淘宝,百度搜索时的自动检索方案.自然想到了使用datalist标签.但是遇到一个bug,经过两天研究.小有结果给大家分享下~~ 首先看bug吧!~ 因为项目最开始测试就是用36 ...
- Hadoop 基本操作
1.关闭安全模式 hadoop dfsadmin -safemode leave
- commonJS — 对象操作(for Object)
for Object github: https://github.com/laixiangran/commonJS/blob/master/src/forObject.js 代码 /** * Cre ...
- Spring Boot 学习
下载安装了如下软件.设置了环境变量. Groovy-Groovy是一种基于JVM(Java虚拟机)的敏捷开发语言,它结合了Python.Ruby和Smalltalk的许多强大的特性,Groovy 代码 ...