从一个视图控制器切换到另一个视图控制器的几种方式

http://blog.csdn.net/itianyi/article/details/8514208

从一个视图控制器切换到另一个视图控制器的几种方式
1,模态(modal)画面的显示方法:
例如iphone通讯录管理程序中,追加新的通讯纪录时,就是使用这种模态画面
例:点击一个按钮,进入另一个界面

- (IBAction)pressAbout:(id)sender {

    XAboutViewController *about=[[[XAboutViewController alloc] initWithNibName:@"XAboutViewController" bundle:nil] autorelease];

    [self presentModalViewController:aboutanimated:YES];//显示模态画面

关闭模态画面的方法:

[self dissmissModalViewControllerAnimationed:YES];

2,SwitchViewController中有2个控制器的属性:BviewController,CViewController
点击按钮之后可以在B与C视图之间切换,也就是ios5开发那本书中的多视图应用程序的例子
使用方法:insertSubview: atIndex:
这种画面跳转方法并非最佳的跳转方法:
实际上并非真的实现了两个画面间的跳转,而是同时启动了2个画面,控制其中哪一个画面显示在前台,哪一个画面显示在后台而已。
这种画面跳转方式有一个很大的缺点,即当画面数量增加时,画面跳转的实现代码将月来越复杂,而且各个画面间不可避免的有相互依赖关系。
3,UITabBarController实现并列画面跳转

    //将5个viewController实例放入TabBar的viewcontrollers属性中    

    self.tabBarController.viewControllers = @[navFrist, navSecond,navThird,navFourth,navFifth];   

    self.window.rootViewController = self.tabBarController;

    [self.window addSubview:self.tabBarController.view];//将根控制器的视图加到应用程序主窗口

4,UINavigationController实现多层画面跳转,在导航控制器中,载入有层级关系的界面

- (IBAction)addRightAction:(id)sender

{

    XAddSymbolViewController *addSymbol=[[[XAddSymbolViewController alloc]initWithNibName:@"XAddSymbolViewController" bundle:nil] autorelease];

    [self.navigationController pushViewController:addSymbolanimated:YES];

}


5.补充:
BeautyDetailedViewController *beautyDetailedVC = [[ BeautyDetailedViewController alloc ] init ];
    [
self presentViewController :beautyDetailedVC animated : YES completion : nil ];
6.    [self.view bringSubviewToFront:_shoppingVC.view];



从一个Controller跳转到另一个Controller时,一般有以下2种: 
1、利用UINavigationController,调用pushViewController,进行跳转;这种采用压栈和出栈的方式,进行Controller的管理。调用popViewControllerAnimated方法可以返回。 


    PickImageViewController *ickImageViewController = [[PickImageViewController alloc] init]; 
    [self.navigationController pushViewController: ickImageViewController animated:true]; 
    [ickImageViewController release]; 




2、利用UIViewController自身的presentModalViewController,进行跳转;调用dismissModalViewControllerAnimated方法可以返回。 
    PickImageViewController *ickImageViewController = [[PickImageViewController alloc] init]; 
    [self presentModalViewController:ickImageViewController animated:YES]; 
//返回 
[self dismissModalViewControllerAnimated:YES];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值