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 ...
随机推荐
- 使用xml来显示获取的mysql数据
mysql test -u test -X -e 'select * from employees where empid = 1' 其中 -X 就是以xml形式显示
- [转]-用Gradle 构建你的android程序
出处:http://www.cnblogs.com/youxilua 前言 android gradle 的插件终于把混淆代码的task集成进去了,加上最近,android studio 用的是gr ...
- 学习日记day7:代码结构规范
1:绝对定位不是随便用的. 2:一定要用相对定位控制文档流,在相对定位里面使用绝对定位控制具体的位置. 3:代码结构尽量简化. 不要加不必要的span: 不要加不必要的类: 4:控制字体样式的类尽量写 ...
- 01 Developing Successful Oracle Applications
varchar2 类型定义时, 个人认为应该选择byte 类型, 即 varchar2(20), oracle 支持的最大的字符串是 varchar2(4000), 同时, 个人认为, 当你定义一个v ...
- mysql 特殊字符
1.倒引号,比如表中有一个字段为desc,在mysql中desc是关键字,如何表明desc是字段呢? 有两种办法:desc使用倒引号引起来,或者在desc前面加上表名,如下:mysql> sel ...
- JavaSE复习_10 多线程复习
△wait()和sleep()的区别: 1.wait():没有等待时间,而sleep()需要有等待时间作为参数. 2.在同步中对于CPU的执行权和锁的处理不同: wait()会释放执行权和锁. ...
- (一)mtg3000常见操作
一.查看MTG3000主控板IP地址: 重启设备后一直跑到shell,用户名和密码都输入admin,然后输入en进入命令行界面,输入sh int可查看设备IP等信息. 2.升级app.web程序
- goLang文件遍历
package main import ( "fmt" "io/ioutil" "os" "path/filepath&q ...
- golang时间
//获取本地location toBeCharge := "2015-01-01 00:00:00" //待转化为时间戳的字符串 注意 这里的小时和分钟还要秒必须写 因为是跟着模板 ...
- JavaScript判断鼠标滑轮是向下还是向上滚动
我们常用的就是鼠标,鼠标中键一般都用于滑动网页,但是网页中很多很炫的效果,使用鼠标滑轮操作更好. 当然对于手机就没有这个设备了,所以就不用考虑手机端的实现方法,手机端有触摸滑动事件. 使用JavaSc ...