【代码笔记】iOS-标题2个图标,点击的时候,页面跳转
一,效果图。

二,工程图。

三,代码
RootViewController.h

#import <UIKit/UIKit.h> @interface RootViewController : UIViewController
{
UIButton * leftButton;
UIButton * rightButton;
UIViewController * firstController;
UIViewController * secondController; }
@end

RootViewController.m

#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //初始化顶部按钮
[self creatHeadView]; //初始化背景图
[self initBackView]; }
#pragma -mark -functions
//初始化背景图
-(void)initBackView
{
firstController = [[UIViewController alloc] init];
firstController.view.backgroundColor = [UIColor redColor];
[self.view addSubview:firstController.view]; secondController = [[UIViewController alloc] init];
secondController.view.backgroundColor = [UIColor blueColor]; }
//初始化顶部按钮
-(void)creatHeadView
{
UIView * headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)]; //左边的按钮
leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 0, 50, 30);
leftButton.tag = 201;
leftButton.enabled = NO;
[leftButton setImage:[UIImage imageNamed:@"left"] forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(doClickHeadActions:) forControlEvents:UIControlEventTouchUpInside];
[headView addSubview:leftButton]; //右边的按钮
rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(50, 0, 50, 30);
rightButton.tag = 301;
[rightButton setImage:[UIImage imageNamed:@"right"] forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(doClickHeadActions:) forControlEvents:UIControlEventTouchUpInside];
[headView addSubview:rightButton]; self.navigationItem.titleView = headView; }
#pragma -mark -doClickActions
-(void)doClickHeadActions:(UIButton *)btn
{
if (btn.tag == 201)
{
[secondController dismissViewControllerAnimated:NO completion:nil];
[self.view addSubview:firstController.view]; [btn setImage:[UIImage imageNamed:@"leftselect"] forState:UIControlStateNormal];
btn.enabled = NO;
[rightButton setImage:[UIImage imageNamed:@"right"] forState:UIControlStateNormal];
rightButton.enabled = YES;
}
else if (btn.tag == 301)
{
[firstController dismissViewControllerAnimated:NO completion:nil];
[self.view addSubview:secondController.view]; [btn setImage:[UIImage imageNamed:@"rightselect"] forState:UIControlStateNormal];
btn.enabled = NO;
[leftButton setImage:[UIImage imageNamed:@"left"] forState:UIControlStateNormal];
leftButton.enabled = YES;
} }
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

【代码笔记】iOS-标题2个图标,点击的时候,页面跳转的更多相关文章
- iOS 极光推送 如何点击推送消息跳转页面
假如你已经集成完了极光,恰好有这个问题不知如何解决,可以看看这篇文章,这篇是针对远程通知的,本地通知大同小异吧. 根据我项目的要求,极光推送跳转指定页面分为两种情况:app在后台情况和app在杀死的情 ...
- 【代码笔记】iOS-UITableView上的button点击事件
代码. ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController < ...
- 【代码笔记】iOS-4个可以单独点击的button
一,效果图. 二,工程图. 三,代码. ViewController.m #import "ViewController.h" @interface ViewController ...
- IOS开发笔记 IOS如何访问通讯录
IOS开发笔记 IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...
- IOS APP的所有图标尺寸规范
转自: http://blog.csdn.net/chonbj/article/details/25133247 像我一样记不住iOS应用图标像素尺寸的开发者不在少数,我经常需要查询不同设备上的应用尺 ...
- 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程
一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...
- 【hadoop代码笔记】hadoop作业提交之汇总
一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...
- 【Hadoop代码笔记】目录
整理09年时候做的Hadoop的代码笔记. 开始. [Hadoop代码笔记]Hadoop作业提交之客户端作业提交 [Hadoop代码笔记]通过JobClient对Jobtracker的调用看详细了解H ...
- 笔记-iOS 视图控制器转场详解(上)
这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...
- <Python Text Processing with NLTK 2.0 Cookbook>代码笔记
如下是<Python Text Processing with NLTK 2.0 Cookbook>一书部分章节的代码笔记. Tokenizing text into sentences ...
随机推荐
- 抓取代理IP
写脚本从指定网站抓取数据的时候,免不了会被网站屏蔽IP.所以呢,就需要有一些IP代理.随便在网上找了一个提供免费IP的网站西刺做IP抓取.本次实践抓取的是其提供的国内匿名代理.可以打开网站查看一下源码 ...
- php实现留言功能
php真的挺好玩的! 先写出前台页面index.php: <!DOCTYPE html> <html lang="en"> <head> < ...
- Autofac - 组件
快到年终了, 最近项目比较悠闲, 就想总结下, 项目中所使用到的一些技术, 以及使用方法. 之前有写过Dapper以及Dapper的一个扩展, 这些也是项目中使用过的. 算是一个温故而知新吧. 代码: ...
- 参数类型params
params参数练习 namespace Test { class Program { static void Main(string[] args) { //params 构造函数声明数组,可变数组 ...
- 九个Console命令,让js调试更简单
一.显示信息的命令 最常用的就是console.log了. 二.占位符 console上述的集中度支持printf的占位符格式,支持的占位符有:字符(%s).整数(%d或%i).浮点数(%f)和对象( ...
- 下一代USB接口将支持双向拔插,于明年亮相
近日,USB接口标准制定组织表示新一代USB接口将于明年年中亮相,而其名称目前被暂定为了USB Type-C.该组织表示USB Type-C标准将允许制造商采用更纤薄的接口设计,在实用性大大提高的同时 ...
- RabbitMQ框架学写笔记-20161130
- linq查询xml
1.加载xml字符串 XElement root = XElement.Parse(@"<?xml version='1.0' encoding='utf-8'?> <It ...
- Scalaz(0) - 写在前面
面向对象编程范畴(OOP)从80年代C++到90年代java的兴起已经经历了几十年的高潮,是不是已经发展到了尽头,该是函数式编程(FP)开始兴旺发达的时候了吧.这样说似乎心眼儿有点坏,可能会得罪当今大 ...
- MyEclipse常用插件使用教程
一.Findbugs 1. 配置 1.1 打开FindBugs视图: Windows => Show View => Other… => FindBugs => Bug Inf ...