//
// SubViewController.h
// UI2_视图切换
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface SubViewController : UIViewController @end //
// SubViewController.m
// UI2_视图切换
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "SubViewController.h" @interface SubViewController () @end @implementation SubViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor cyanColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(20, 300, self.view.frame.size.width-40, 50);
btn.backgroundColor = [UIColor whiteColor];
[btn setTitle:@"视图切换" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
} - (void)btnClicked
{
NSLog(@"-----");
if (self.view.superview) {
[self.view removeFromSuperview];
}
} - (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
//
// RootViewController.h
// UI2_视图切换
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface RootViewController : UIViewController @end //
// RootViewController.m
// UI2_视图切换
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "RootViewController.h"
#import "SubViewController.h" @interface RootViewController ()
{
SubViewController *_svc;
}
@end @implementation RootViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor]; _svc = [[SubViewController alloc] init]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(20, 200, self.view.frame.size.width-40, 50);
[btn setTitle:@"视图切换" forState:UIControlStateNormal];
btn.backgroundColor = [UIColor whiteColor];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
} - (void)btnClicked
{
[self.view addSubview:_svc.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
//
// AppDelegate.m
// UI2_视图切换
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "RootViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
RootViewController *rootViewController = [[RootViewController alloc] init];
self.window.rootViewController = rootViewController;
return YES;
}

UI2_视图切换ViewController的更多相关文章

  1. UI2_视图切换

    // // ViewController.m // UI2_视图切换 // // Created by zhangxueming on 15/7/1. // Copyright (c) 2015年 z ...

  2. iOS开发系列--视图切换

    概述 在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单.在iOS开发中常用的视图切换有三种,今天我们将一一介绍: UITabBarController ...

  3. pushViewController addSubview presentModalViewController视图切换

    1.pushViewController和popViewController来进行视图切换,首先要确保根视图是NavigationController,不然是不可以用的, pushViewContro ...

  4. UI3_视图切换

    // // ViewController.m // UI3_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 z ...

  5. UI1_ViewController视图切换及Appdelegate

    // // ThirdViewController.h // UI1_ViewController视图切换及Appdelegate // // Created by zhangxueming on 1 ...

  6. Tabbar视图切换,返回上一视图,添加item

    前面有一篇博文iOS学习之Tab Bar的使用和视图切换 这是在AppDelegate里使用Tabbar,这样的程序打开就是TabbarView了,有时候我们需要给程序做一些帮助页面,或者登录页面,之 ...

  7. IPhone多视图切换

    处理IPhone多个view切换是我们常遇到的问题,接下来有个比较实用的方法: 而且还附有创建空项目,内存告急处理和动画效果的实现! 具体步骤: 1.创建一个空的项目,然后添加一个ViewContro ...

  8. iOS:视图切换的第一种方式:模态窗口

    一.UIModalController:模态窗口(一个控制器模态出另一个控制器的模态窗口) 当我们在view controller A中模态显示view controller B的时候,A就充当pre ...

  9. ios 视图切换翻页效果

    本文写的是视图切换,涉及到的内容有 1.实现代码添加Navigation Bar  Toolbal: 2.实现在Navigation Bar和Toolbar上用代码添加Bar Button Item: ...

随机推荐

  1. linux C(hello world)程序调试

    程序的调试(先得安装gdb工具,以root身份执行命令:sudo apt-get install gdb) 程序的调试是一个很重要的环节,windows IDE下那些强大的调试功能,Linux以什么来 ...

  2. wget 命令用法详解

    wget是在Linux下开发的开放源代码的软件,作者是Hrvoje Niksic,后来被移植到包括Windows在内的各个平台上.它有以下功能和特点:(1)支持断点下传功能:这一点,也是网络蚂蚁和Fl ...

  3. Beautyacticle

    Original: https://github.com/rizhilee/Beautyacticle Backup: https://github.com/eltld/Beautyacticle

  4. Circle-Progress-View

    https://github.com/jakob-grabner/Circle-Progress-View

  5. Android游戏背景音乐音效音量控制

    游戏音效就是我们在玩游戏时出现的音乐,这个也是每个游戏必备的一部分,但有是你做游戏的背景音乐有间断的感觉的话,我们可以用 getCurrentPosition()这个方法来判断一下声音播放的偏移.其实 ...

  6. [Angular2 Router] Programmatic Router Navigation via the Router API - Relative And Absolute Router Navigation

    In this tutorial we are going to learn how to navigate programmatically (or imperatively) by using t ...

  7. Android中如何实现多行、水平滚动的分页的Gridview?

    功能要求: (1)比如每页显示2X2,总共2XN,每个item显示图片+文字(点击有链接). 如果单行水平滚动,可以用Horizontalscrollview实现. 如果是多行水平滚动,则结合Grid ...

  8. VC编译连接选项详解(转)

    大家可能一直在用VC开发软件,但是对于这个编译器却未必很了解.原因是多方面的.大多数情况下,我们只停留在“使用”它,而不会想去“了解”它.因为它只是一个工具,我们宁可把更多的精力放在C++语言和软件设 ...

  9. 10905 - Children's Game

    4th IIUC Inter-University Programming Contest, 2005 A Children’s Game Input: standard input Output: ...

  10. 沈逸老师PHP魔鬼特训笔记(7)--我叫什么名字

    一.生成文件夹. mkdir():--新建目录 bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false ...