使用容器控制器控制另外两个控制器的view交换
建三个UIViewController 的子控制器,其中一个为根控制器,另外两个控制器的视图作为切换对象
AppDelegate中代码
//AppDelegate.h中代码
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (retain, nonatomic) UIWindow *window; @end
//AppDelegate.m中代码
根视图控制器RootViewController中代码
//RootViewController.h中代码
#import <UIKit/UIKit.h> @interface RootViewController : UIViewController @end
//RootViewController.m中代码
#import "RootViewController.h"
#import "BlueViewController.h"
#import "RedViewController.h"
@interface RootViewController ()
{
BlueViewController *_blueview;
RedViewController *_redview;
}
@end @implementation RootViewController
-(void)dealloc
{
[_blueview release];
[_redview release];
[super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)change:(UIButton *)button
{
if (_blueview.view.superview !=nil) {
[_blueview.view removeFromSuperview];
[self.view addSubview:_redview.view];
}else{
[_redview.view removeFromSuperview];
[self.view addSubview:_blueview.view];
}
} - (void)viewDidLoad
{
[super viewDidLoad];
//蓝色视图控制器的创建
_blueview = [[BlueViewController alloc] init];
_blueview.view.frame = CGRectMake(, , , ); //添加到根控制器
[self.view addSubview:_blueview.view]; //红色视图控制器创建
_redview = [[RedViewController alloc] init];
_redview.view.frame = CGRectMake(, , , );
//添加到根控制器
[self.view addSubview:_redview.view]; //在根控制器上创建带触发交换事件的按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(, , , );
[button setTitle:@"交换" forState:UIControlStateNormal];
button.backgroundColor = [UIColor blackColor];
[button addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// Do any additional setup after loading the view.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
BlueViewController中代码
//BlueViewController.h中代码
#import <UIKit/UIKit.h> @interface BlueViewController : UIViewController @end
//BlueViewController.m中代码
#import "BlueViewController.h" @interface BlueViewController () @end @implementation BlueViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
// Do any additional setup after loading the view.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
RedViewController
//RedViewController.h中代码
#import <UIKit/UIKit.h> @interface RedViewController : UIViewController @end
//RedViewController.m中代码
#import "RedViewController.h" @interface RedViewController () @end @implementation RedViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
// Do any additional setup after loading the view.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
使用容器控制器控制另外两个控制器的view交换的更多相关文章
- ThinkPHP之中利用commom被继承控制器控制访问每一个控制器方法都需要验证是否已经登录!
防止 <?php namespace Home\Controller; use Think\Controller; class CommonController extends Controll ...
- iOS不得姐项目--推荐关注模块(一个控制器控制两个tableView),数据重复请求的问题,分页数据的加载,上拉下拉刷新(MJRefresh)
一.推荐关注模块(一个控制器控制两个tableView) -- 数据的显示 刚开始加载数据值得注意的有以下几点 导航控制器会自动调整scrollView的contentInset,最好是取消系统的设置 ...
- STM32驱动ILI9341控制器控制TFTLCD显示
STM32驱动ILI9341控制器控制TFTLCD显示 一.用STM32控制TFTLCD显示的编程方法,在编程驱动TFTLCD液晶显示器之前,我们先熟悉以下概念: 1.色彩深度,这是一个与TFTLCD ...
- 循环灯控制器,该控制器控制红、绿、黄三个发光管循环发亮(VHDL语言)
设计一个循环灯控制器,该控制器控制红.绿.黄三个发光管循环发亮.要求红发光管亮2秒,绿发光管亮3秒,黄发光管亮1秒.(假设外部提供频率为1MHz的方波信号) library ieee; use iee ...
- ios开发级联菜单(利用父子控制器--两个菜单封装为两个子控制器来实现)
一:1:级联菜单可以使用两个tableView来实现,也可以利用父子控制器,两个控制器来实现,根视图控制器作为两个控制器的父控制器,来管理两个子控制器.2:将左右菜单分别交给两个控制器去管理,对于一些 ...
- PID控制器(比例-积分-微分控制器)- I
形象解释PID算法 小明接到这样一个任务: 有一个水缸点漏水(而且漏水的速度还不一定固定不变),要求水面高度维持在某个位置,一旦发现水面高度低于要求位置,就要往水缸里加水. 小明接到任务后就一直守在水 ...
- SpringMVC传统风格控制器和基于注解的控制器
SpringMVC的DispatcherServlet 之前说过springMVC是使用Servlet作为控制器,就是这个用于调度的DispatcherServlet了.这个是servlet,可以根据 ...
- [Xcode 实际操作]三、视图控制器-(3)使用UINavigationController视图控制器
目录:[Swift]Xcode实际操作 本文将演示导航视图控制器的使用. 选择项目导航区的资源文件夹.需要导入两张图片,作为选项卡控制器的图标. [+]->[Import]->选择图片-& ...
- 前端控制器是整个MVC框架中最为核心的一块,它主要用来拦截符合要求的外部请求,并把请求分发到不同的控制器去处理,根据控制器处理后的结果,生成相应的响应发送到客户端。前端控制器既可以使用Filter实现(Struts2采用这种方式),也可以使用Servlet来实现(spring MVC框架)。
本文转自http://www.cnblogs.com/davidwang456/p/4090058.html 感谢作者 前端控制器是整个MVC框架中最为核心的一块,它主要用来拦截符合要求的外部请求,并 ...
随机推荐
- 面向对象编程(OOP)基础之UML基础
在我们学习OOP过程中,难免会见到一些结构图~各种小框框.各种箭头.今天小猪就来简单介绍一下这些框框箭头的意思——UML. UML定义的关系主要有:泛化(继承).实现.依赖.关联.聚合.组合,这六种关 ...
- 转载——PLSQL developer 连接不上64位Oracle 解决办法
前两天刚下载了oracle 11g 64位的最新版本,安装成功之后,再安装PLSQL.结果使用PLSQL访问数据库时,死活连接不上.报错如下: Could not load "……\bin\ ...
- 利用LM神经网络和决策树去分类
# -*- coding: utf-8 -*- import pandas as pd from scipy.interpolate import lagrange from matplotlib i ...
- C#窗体的加载等待(BackgroundWorker控件)实现
窗体拉一个Button按钮和一个加载等待显示的label, label默认隐藏,点击按钮时显示这个label,加载完再隐藏 1.工具箱拉BackgroundWorker控件到窗体 2.backgrou ...
- php头像上传并裁剪支持3个尺寸
源码下载
- POJ 1777 mason素数
题目大意: 给定数列 a1 , a2 , ... , an 希望找到一个 N = sigma(ai^ki) , (0<=ki<10) ,ki可随自己定为什么 只要保证N的因子和可以表示 ...
- xcode6 ios launchimage
1.点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image" 2.右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以及低版本的ios系 ...
- 分布式一致性原理—BASE
定义 BASE是BasicallyAvailable(基本可用).Soft state(软状态)和Eventually consistent(最终一致性)三个短语的简写,是由来自eBay的架构师Dan ...
- java基础之hashmap
Hashmap是一种非常常用的.应用广泛的数据类型,最近研究到相关的内容,就正好复习一下.网上关于hashmap的文章很多,但到底是自己学习的总结,就发出来跟大家一起分享,一起讨论. 1.hashma ...
- 关于查询oracle in >1000 的讨论
https://q.cnblogs.com/q/88538/