建三个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. iOS通过openURL打开原生应用与页面(包括电话,短信,safari等)

    [[UIApplication sharedApplication] openURL:url];通过给url不同的值,可以实现调用系统自带 电话/短信/邮箱/浏览器/... 1.调用 电话phone[ ...

  2. bzoj3594: [Scoi2014]方伯伯的玉米田

    dp新优化姿势... 首先,当我们拔高时,一定右端点是n最优.因为如果右端点是r,相当于降低了r之后玉米的高度.显然n更优. 那么可以dp.dp[i][j]表示前i个拔高j次的LIS.dp[i][j] ...

  3. C char** 的一点儿理解

    理解是就是char** 相当于字符串数组,我以往纠结于该用 **arr还是*arr还是 (*arr),还是(**arr): 对于**arr而言:*arr代表数组的最开头,也就是第一个字串的内容.**a ...

  4. nginx查看配置文件nginx.conf路径

      当你执行 nginx -t 得时候,nginx会去测试你得配置文件得语法,并告诉你配置文件是否写得正确,同时也告诉了你配置文件得路径:  # nginx -t nginx: the configu ...

  5. Win7 Print Spooler服務自动关闭

    对于Win7系统而言,该问题通常是安装了错误的打印驱动引起的,Win7系统为了保护其它进程不受干扰,自动关闭了打印服务. 解决方法就是: a> 把不用的打印机删掉. b> 确保你安装了正确 ...

  6. 查看UI调试界面利器 revealapp

    官网 http://revealapp.com 做iOS的开发,UI是非常非常重要的一环.调试时我们一般用模拟器,提交前用真机做测试.用模拟器来调试UI效果虽然快捷方便,但有时仍然希望有更强大的工具来 ...

  7. 高效率JAVA实现斐波那契

    import java.util.Scanner;public class Solution { public static int Fibonacci(int n) { int first = 0, ...

  8. VMware-workstation-full-10.0.3-1895310 CN

    Name: VMware-workstation-full-10.0.3-1895310.exe发行日期: 2014-07-01内部版本号: 1895310文件大小: 491 MB文件类型: exe ...

  9. 解决问题:centos虚拟机安装好nginx,本机无法访问

    阵子在虚拟机上装好了centos5.3,并配好了nginx+php+mysql,但是本机就是无法访问.一直就没去折腾了.具体情况如下1.本机能ping通虚拟机2.虚拟机也能ping通本机3.虚拟机能访 ...

  10. viewController的自动扩展属性导致TableViewGroupStyle时向上填充

    self.automaticallyAdjustsScrollViewInsets = NO; 需设置这个属性