标签栏 UITabBarController
导航栏UINavigationController
3个ViewController,一个控制蓝色,一个控制黄色,第三个再按下切换视图按钮时在两个视图间
切换。
根控制器任务获取多个视图,根据用户输入向用户提供适当的视图。
UINavigationController , UITabBarController , UIViewController
大部分屏幕都由一个内容视图组成,每个内容视图都有自己的控制器和输出口和动作。
如 触摸标签栏会转到标签栏控制器中,触摸其他位置会转到当前显示的内容视图对应的控制器中。
根控制器控制一个内容视图,内容视图包含一个位于屏幕底部的工具栏。
根控制器加载一个蓝色视图控制器,讲蓝色视图加载为根控制器视图的子视图。
切换视图时切换出蓝色视图控制器,然后加载黄色视图控制器,然后实例化黄色控制器。
Window-Based Application
一个窗口,委托
创建3个UIViewController
RootViewController
Blue+Yellow(带有视图)
应用程序委托AppDelegate:
appDelegate.h:
#import <UIKit/UIKit.h>
@class SwitchViewController;
@interface AppDelegate:...{
SwitchViewController *switchViewController;
}
@property (nonatomic,retain) IBOutlet SwitchViewController *switchViewController;
@end
appDelegate.m:
#import "SwitchViewController.h"
@synthesize switchViewController;
-(void)applicationDidFinishLaunching:(UIApplication *)application{
[window addSubview:switchViewController.view];
}
-(void)dealloc{
[switchViewController release];
}
@end
switchViewController.h
@class BlueController;
@class YellowController;
@interface SwitchViewController:UIViewController{
YellowController* yellow;
BlueController* blue;
}
@property (retain,noatomic) YellowController* yellowController;
...
-(IBAction)switchView:(id)sender;
@end
SwitchViewController.m
#import "Blue.h"
..
@synthesize yellow;
-(void)viewDidLoad{
BlueViewController *blueController=[[BlueViewController alloc]initWithNibName:@"BlueView"
bundle:nil];
self.blueController=blueController;
[self.view InsertSubView:blueController.view atIndex:0];
[blueController release];
[super viewDidLoad];
}
-(IBAction)switchView:(id)sender{
if(self.yellowControler.view.superview==nil)
{
YellowController *yellowControler=[[YellowController alloc]initWithNibName:@"yellowController" bundle:nil ];
self.yellowController=yellowController;
[yellowController release];
}
[blueViewController.view removeFromSuperview];
[self.view insertSubview:yellowController.view atIndex:0];
}
------------------- alert
UIAlertView * alert=[[UIAlertView alloc] initWithTitle:@"yellow" message:@"" delegate:nil
delegate:nil cancelButtonTitle:@"" otherButtonTitles:nil];
[alert show];
[alert release];
------------------- animation
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:yes];
[UIView commitAnimations]