iphone视图间跳转之一:自定义视图控制器
来源:互联网 发布:dnf账号数据出现异常 编辑:程序博客网 时间:2024/05/22 09:04
本文将介绍两个视图之间切换,在介绍它之间,我们先理解几个概念。
我们在创建的每个View-based Application程序的都会生成一个XXXAppDelegate的头文件与源文件。
如下:
#import <UIKit/UIKit.h>@class Hello_WorldViewController;@interface Hello_WorldAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; Hello_WorldViewController *viewController;}@property (nonatomic, retain) IBOutlet UIWindow *window;@property (nonatomic, retain) IBOutlet Hello_WorldViewController *viewController;@end
从上面可以看出它拥有一个UIWindow、以及XXXXViewController的成员。UIWindow可以认为它是一个iphone无任何内容的窗口,XXXXViewController是程序第一次加载到UIWindow需要显示的视图控制器,即根视图控制器,里面可以放其它视图,作为其它视图的跟视图控制器。
下面我们写个测试来说明这一切,先看效果图:
主要代码:
#import <UIKit/UIKit.h>#import "BlueViewController.h"#import "YellowViewController.h"@interface MutilViewSwitchViewController : UIViewController {YellowViewController *yellowViewController;BlueViewController *blueViewController;}@property (nonatomic, retain) YellowViewController *yellowViewController;@property (nonatomic, retain) BlueViewController *blueViewController;-(IBAction) switchViews:(id)sender;@end#import "MutilViewSwitchViewController.h"@implementation MutilViewSwitchViewController@synthesize yellowViewController;@synthesize blueViewController;-(IBAction) switchViews:(id)sender {if (self.yellowViewController.view.superview == nil) {if (self.yellowViewController.view == nil) {YellowViewController *yellowController = [[YellowViewController alloc] initWithNibName:@"YellowViewController" bundle:nil];self.yellowViewController = yellowController;[yellowController release];}[blueViewController.view removeFromSuperview];[self.view insertSubview:yellowViewController.view atIndex:0];} else {if (self.blueViewController.view == nil) {BlueViewController *blueController = [[BlueViewController alloc] initWithNibName:@"BlueViewController" bundle:nil];self.blueViewController = blueController;[blueController release];}[yellowViewController.view removeFromSuperview];[self.view insertSubview:blueViewController.view atIndex:0];}}/*// The designated initializer. Override to perform setup that is required before the view is loaded.- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { // Custom initialization } return self;}*//*// Implement loadView to create a view hierarchy programmatically, without using a nib.- (void)loadView {}*/// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.- (void)viewDidLoad {BlueViewController *blueController = [[BlueViewController alloc] initWithNibName:@"BlueViewController" bundle:nil];self.blueViewController = blueController;[self.view insertSubview:blueController.view atIndex:0];[blueController release]; [super viewDidLoad];}/*// Override to allow orientations other than the default portrait orientation.- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait);}*/- (void)didReceiveMemoryWarning {// Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning];// Release any cached data, images, etc that aren't in use.}- (void)viewDidUnload {// Release any retained subviews of the main view.// e.g. self.myOutlet = nil;self.yellowViewController = nil;self.blueViewController = nil;}- (void)dealloc {[yellowViewController release];[blueViewController release]; [super dealloc];}@end
- iphone视图间跳转之一:自定义视图控制器
- iphone视图间跳转之二:标签栏控制器
- iphone视图间跳转之三:导航栏控制器
- 【iphone应用开发】iPhone应用开发之一:窗口,视图,视图控制器和UIKit基础
- 【iphone应用开发】iPhone应用开发之一:窗口,视图,视图控制器和UIKit基础
- 【iphone应用开发】iPhone应用开发之一:窗口,视图,视图控制器和UIKit基础
- 自定义视图控制器容器
- iPhone第一节:视图控制器和基本视图
- iPhone应用开发之一:窗口,视图,视图控制器和UIKit基础
- iPhone应用开发之一:窗口,视图,视图控制器和UIKit基础
- UISplitViewController 分割视图控制器,自定义左右视图控制器视图大小
- UI第三节 自定义视图,视图控制器
- 第三讲:⾃自定义视图、视图控制器
- 自定义视图、使用视图控制器知识点总结
- UI 第三天 自定义视图 视图控制器
- UI基础-自定义视图、视图控制器
- 自定义视图,视图控制器的使用
- storyboard自定义视图控制器切换
- CKEditor 3.6入门--在 jsp 中通过自定义标签调用
- AES加密之openssl使用(2)
- hdu1059Dividing 多重背包二进制优化
- 【python】【scrapy】使用方法概要(一)
- javascript中的对象
- iphone视图间跳转之一:自定义视图控制器
- poj1182 并查集 食物链
- 【python】【scrapy】使用方法概要(三)
- ffmpeg使用指南相关网址
- 下拉菜单--字体练习
- 【python】【scrapy】使用方法概要(二)
- 703n无法进入路由管理界面reset无效重刷方法
- 【python】【scrapy】使用方法概要(四)
- 文本分类算法之决策树.ID3实现