建三个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交换的更多相关文章

  1. ThinkPHP之中利用commom被继承控制器控制访问每一个控制器方法都需要验证是否已经登录!

    防止 <?php namespace Home\Controller; use Think\Controller; class CommonController extends Controll ...

  2. iOS不得姐项目--推荐关注模块(一个控制器控制两个tableView),数据重复请求的问题,分页数据的加载,上拉下拉刷新(MJRefresh)

    一.推荐关注模块(一个控制器控制两个tableView) -- 数据的显示 刚开始加载数据值得注意的有以下几点 导航控制器会自动调整scrollView的contentInset,最好是取消系统的设置 ...

  3. STM32驱动ILI9341控制器控制TFTLCD显示

    STM32驱动ILI9341控制器控制TFTLCD显示 一.用STM32控制TFTLCD显示的编程方法,在编程驱动TFTLCD液晶显示器之前,我们先熟悉以下概念: 1.色彩深度,这是一个与TFTLCD ...

  4. 循环灯控制器,该控制器控制红、绿、黄三个发光管循环发亮(VHDL语言)

    设计一个循环灯控制器,该控制器控制红.绿.黄三个发光管循环发亮.要求红发光管亮2秒,绿发光管亮3秒,黄发光管亮1秒.(假设外部提供频率为1MHz的方波信号) library ieee; use iee ...

  5. ios开发级联菜单(利用父子控制器--两个菜单封装为两个子控制器来实现)

    一:1:级联菜单可以使用两个tableView来实现,也可以利用父子控制器,两个控制器来实现,根视图控制器作为两个控制器的父控制器,来管理两个子控制器.2:将左右菜单分别交给两个控制器去管理,对于一些 ...

  6. PID控制器(比例-积分-微分控制器)- I

    形象解释PID算法 小明接到这样一个任务: 有一个水缸点漏水(而且漏水的速度还不一定固定不变),要求水面高度维持在某个位置,一旦发现水面高度低于要求位置,就要往水缸里加水. 小明接到任务后就一直守在水 ...

  7. SpringMVC传统风格控制器和基于注解的控制器

    SpringMVC的DispatcherServlet 之前说过springMVC是使用Servlet作为控制器,就是这个用于调度的DispatcherServlet了.这个是servlet,可以根据 ...

  8. [Xcode 实际操作]三、视图控制器-(3)使用UINavigationController视图控制器

    目录:[Swift]Xcode实际操作 本文将演示导航视图控制器的使用. 选择项目导航区的资源文件夹.需要导入两张图片,作为选项卡控制器的图标. [+]->[Import]->选择图片-& ...

  9. 前端控制器是整个MVC框架中最为核心的一块,它主要用来拦截符合要求的外部请求,并把请求分发到不同的控制器去处理,根据控制器处理后的结果,生成相应的响应发送到客户端。前端控制器既可以使用Filter实现(Struts2采用这种方式),也可以使用Servlet来实现(spring MVC框架)。

    本文转自http://www.cnblogs.com/davidwang456/p/4090058.html 感谢作者 前端控制器是整个MVC框架中最为核心的一块,它主要用来拦截符合要求的外部请求,并 ...

随机推荐

  1. HBase vs. BigTable Comparison - HBase对比BigTable

    HBase vs. BigTable Comparison HBase is an open-source implementation of the Google BigTable architec ...

  2. hduacm 5104

    http://acm.hdu.edu.cn/show #include <cstdio> #include <cstring> #include <algorithm&g ...

  3. 完美实现自己的GetProcAddress函数(转载)

    我们知道kernel32.dll里有一个GetProcAddress函数,可以找到模块中的函数地址,函数原型是这样的: WINBASEAPI FARPROC WINAPI GetProcAddress ...

  4. bzoj 2326: [HNOI2011]数学作业

    #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #defin ...

  5. FLASH AS 不显示中文

    我修改一个as游戏,发现公告显示不了,整整折腾了2天. flash TextField 汉字不显示,英文会显示,如果是汉字夹杂数字,只把数字显示了,汉字被忽略了.   有人说嵌入字体,网上一搜索,好麻 ...

  6. 面试题目-c和c++的区别

    在很大程度上,标准C++是标准C的超集.实际上,所有C程序也是C++程序,然而,两者之间有少量区别.下面简要介绍一下最重要的区别.    1. 在C++中,局部变量可以在一个程序块内在任何地方声明,在 ...

  7. AOP面向切面编程

    1.AOP Aop(aspect object programming)面向切面编程 功能: 让关注点代码与业务代码分离! 关注点 重复代码就叫做关注点: 切面 关注点形成的类,就叫切面(类)! 面向 ...

  8. <转>提高iOS开发效率的方法和工具

    介绍 这篇文章主要是介绍一下我在iOS开发中使用到的一些可以提升开发效率的方法和工具. IDE 首先要说的肯定是IDE了,说到IDE,Xcode不能跑,当然你也可能同时在使用AppCode等其他的ID ...

  9. 经典线程同步 关键段CS

    上一篇<秒杀多线程第四篇 一个经典的多线程同步问题>提出了一个经典的多线程同步互斥问题,本篇将用关键段CRITICAL_SECTION来尝试解决这个问题. 本文首先介绍下如何使用关键段,然 ...

  10. 发布Restful服务时出现IIS 指定了身份验证方案错误时的解决方案(IIS specified authentication schemes)

    发布RESTful服务,当访问.svc文件时出现如下错误时: IIS 指定了身份验证方案“IntegratedWindowsAuthentication, Anonymous”,但绑定仅支持一种身份验 ...