UINavigationController详解二(转)页面切换和SegmentedController
原文出自:http://blog.csdn.net/totogo2010/article/details/7682433,非常感谢。
1、RootView 跳到SecondView
首先我们需要新一个View。新建SecondView,按住Command键然后按N,弹出新建页面,我们新建SecondView
2、为Button 添加点击事件,实现跳转
在RootViewController.xib中和RootViewController.h文件建立连接

在RootViewController.m中实现代码,alloc一个SecondViewController,用pushViewController到navigationController中去,并为
SecondViewController这是title为 secondView.title =@"Second View"; 默认情况下,titie为下个页面返回按钮的名字。
- - (IBAction)gotoSecondView:(id)sender {
 - SecondViewController *secondView = [[SecondViewController alloc] init];
 - [self.navigationController pushViewController:secondView animated:YES];
 - secondView.title = @"Second View";
 - }
 
这是点击GotoSecondView 按钮,出现

这就是SecondView了。
3、添加segmentedController
在nav bar这样的效果是如何实现的呢?

这就是segmentedController。
3.1在RootViewController.m的viewDidLoad添加如下代码:
- NSArray *array = [NSArray arrayWithObjects:@"鸡翅",@"排骨", nil];
 - UISegmentedControl *segmentedController = [[UISegmentedControl alloc] initWithItems:array];
 - segmentedController.segmentedControlStyle = UISegmentedControlSegmentCenter;
 - [segmentedController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
 - self.navigationItem.titleView = segmentedController;
 
3.2[segmentedController addTarget:selfaction:的实现
- -(void)segmentAction:(id)sender
 - {
 - switch ([sender selectedSegmentIndex]) {
 - case 0:
 - {
 - UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了鸡翅" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
 - [alter show];
 - }
 - break;
 - case 1:
 - {
 - UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了排骨" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
 - [alter show];
 - }
 - break;
 - default:
 - break;
 - }
 - }
 
这样就能响应鸡翅和排骨按钮了
4、自定义backBarButtonItem
左上角的返回上级View的barButtonitem的名字是上级目录的Title,如果title或者适合做button的名字,怎么办呢?我们可以自己定义
代码如下:
- UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"根视图" style:UIBarButtonItemStyleDone target:nil action:nil];
 - self.navigationItem.leftBarButtonItem = backButton;
 
效果:

6、自定义title
UINavigationController的title可以用别view替代,比如用UIButton UILable等,下面我用UIButton.
在SecondViewController.m中添加下面如下。
- - (void)viewDidLoad
 - {
 - [super viewDidLoad];
 - UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect];
 - [button setTitle: @"自定义title" forState: UIControlStateNormal];
 - [button sizeToFit];
 - self.navigationItem.titleView = button;}
 
运行程序,goto secondView,运行效果

UINavigationController详解二(转)页面切换和SegmentedController的更多相关文章
- [转]iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController
		
转载地址:http://blog.csdn.net/totogo2010/article/details/7682433 iOS学习之UINavigationController详解与使用(一)添加U ...
 - iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController
		
iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem是上篇,我们接着讲UINavigationController的重要作用,页面的管理和切换. ...
 - iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
		
http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...
 - [转]iOS学习之UINavigationController详解与使用(三)ToolBar
		
转载地址:http://blog.csdn.net/totogo2010/article/details/7682641 iOS学习之UINavigationController详解与使用(二)页面切 ...
 - UINavigationController详解一(转)UIBarButtonItem
		
本文出自:http://www.cnblogs.com/smileEvday/archive/2012/05/14/2495153.html 特别感谢. 1.UINavigationControlle ...
 - iOS学习之UINavigationController详解与使用(三)ToolBar
		
1.显示Toolbar 在RootViewController.m的- (void)viewDidLoad方法中添加代码,这样Toobar就显示出来了. [cpp] view plaincopy [ ...
 - Shiro 安全框架详解二(概念+权限案例实现)
		
Shiro 安全框架详解二 总结内容 一.登录认证 二.Shiro 授权 1. 概念 2. 授权流程图 三.基于 ini 的授权认证案例实现 1. 实现原理图 2. 实现代码 2.1 添加 maven ...
 - .NET DLL 保护措施详解(二)关于性能的测试
		
先说结果: 加了缓存的结果与C#原生代码差异不大了 我对三种方式进行了测试: 第一种,每次调用均动态编译 第二种,缓存编译好的对象 第三种,直接调用原生C#代码 .net dll保护系列 ------ ...
 - PopUpWindow使用详解(二)——进阶及答疑
		
相关文章:1.<PopUpWindow使用详解(一)——基本使用>2.<PopUpWindow使用详解(二)——进阶及答疑> 上篇为大家基本讲述了有关PopupWindow ...
 
随机推荐
- Windows7下 配置 Apache + PHP + MySQL + Zend Studio配置
			
相关软件下载: Apache 版本:(httpd-2.2.25) PHP ...
 - MFC之向导页、消息框、文件选择、字体、颜色(三)
			
属性页对话框的分类 属性页对话框想必大家并不陌生,XP系统中桌面右键点属性,弹出的就是属性页对话框,它通过标签切换各个页面.另外,我们在创建MFC工程时使用的向导对话框也属于属性页对话框,它通过点击“ ...
 - 解决在VMware中安装64位系统时“此主机具有虚拟化支持能力的,但虚拟化技术被禁用”的方法
			
您已经配置此虚拟机使用64位客户操作系统.然而,64位操作系统不可用.此主机具有虚拟化支持能力的,但虚拟化技术被禁用.这通常是因为虚拟化技术已经在BIOS /固件设置或禁用或主机没有权限改变此设置. ...
 - imx6 RGB LCD
			
imx6dl需要支持lcd接口的屏,imx6dl的datasheet并没有明确的说明lcd相关的配置,只在Display Content Integrity Checker (DCIC)一章中介绍.本 ...
 - 我的工具箱之VNC
			
下载地址:http://pan.baidu.com/s/1bovEoZ9 这个工具可以连接到Linux并进行可视化操作. 如何搭建VNC环境请见 在centOS上安装VNC 2016年2月26日11: ...
 - Mybatis的分页插件PageHelper
			
Mybatis的分页插件PageHelper 项目地址:http://git.oschina.net/free/Mybatis_PageHelper 文档地址:http://git.oschina. ...
 - [BS-15] Values of type 'NSInteger' should not be used as format arguments
			
Values of type 'NSInteger' should not be used as format arguments 苹果app支持arm64以后会有一个问题:NSInteger变成64 ...
 - [转帖]Speed-BI数据分析案例:2016年8月汽车销量排行榜
			
[转帖]Speed-BI数据分析案例:2016年8月汽车销量排行榜 据中国汽车工业协会统计分析,2016年8月,乘用车市场表现较好,当月销量环比和同比均呈较快增长.1-8月,乘用车销量总体呈稳定增长, ...
 - Power-BI 主要城市商品房销售分析
			
经常在网上看到有关房价的讨论,房价可能真的悬了,高房价撑不了多久,一线城市房价远高于国际,暴涨游戏该结束了,等等.那么近年来房价整体上究竟是一个什么样的状态?今天我们撇开宏观经济要素,来看看近年来主要 ...
 - 第四篇 Integration Services:增量加载-Updating Rows
			
本篇文章是Integration Services系列的第四篇,详细内容请参考原文. 回顾增量加载记住,在SSIS增量加载有三个使用案例:1.New rows-add rows to the dest ...