ios学习:页面跳转(present)

 

 

  1 //
  2 //  TWFXSecondViewController.m
  3 //  DemoMultiView
  4 //
  5 //  Created by Lion User on 12-12-24.
  6 //  Copyright (c) 2012年 Lion User. All rights reserved.
  7 //
  8 
  9 #import "TWFXSecondViewController.h"
 10 #import "TWFXThirdViewController.h"
 11 
 12 @interface TWFXSecondViewController ()
 13 
 14 @end
 15 
 16 @implementation TWFXSecondViewController
 17 @synthesize thirdViewController;
 18 
 19 
 20 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
 21 {
 22     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 23     if (self) {
 24         // Custom initialization
 25     }
 26     return self;
 27 }
 28 
 29 - (void)viewDidLoad
 30 {
 31     [super viewDidLoad];
 32     // Do any additional setup after loading the view from its nib.
 33 }
 34 
 35 - (void)didReceiveMemoryWarning
 36 {
 37     [super didReceiveMemoryWarning];
 38     // Dispose of any resources that can be recreated.
 39 }
 40 
 41 
 42 
 43 /*
 44  多视图切换,如果是从A视图跳转到B视图,那么A表示当前视图,B表示将要跳转到视图
 45  多视图跳转可以理解为有两部分:从A跳到B, B 返回 A.注意,是返回,不是重新发起跳转
 46  这里是第二阶段:从B返回A
 47  
 48  self.presentingViewController 在跳转发生后有效,表示B试图的上一个视图,在这里为A视图
 49  self.presentedViewController 在跳转发生后有效,表示B视图的下一个视图,在这里为nil,以为并没有发生跳转
 50  self.parentViewController表示B的父试图,也为nil
 51  */
 52 -(IBAction)btnClicGoBack:(UIButton *)sender{
 53     
 54     
 55     void(^task)() = ^{
 56         
 57         NSLog(@"2self: %@",self);
 58         NSLog(@"2back ed%@",self.presentedViewController);
 59         NSLog(@"2back ing%@",self.presentingViewController);
 60         //  NSLog(@"back par%@",self.parentViewController);
 61         printf("\n\n");
 62         
 63     };
 64     
 65    // task();
 66     
 67     //跳转完成后调用completion,此时,当前视图已被销毁,self.presentedViewController self.presentingViewController都为nil
 68     [self dismissViewControllerAnimated:YES completion:nil];
 69     
 70     task();//此时,当前视图还没被销毁,self.presentingViewController 表示上一个视图
 71 
 72 }
 73 
 74 - (IBAction)btnClickTraToFirst:(UIButton *)sender {
 75 }
 76 
 77 
 78 /*
 79  这里表示从B视图跳到C视图
 80  */
 81 - (IBAction)btnClickTra:(UIButton *)sender {
 82     
 83     if (self.thirdViewController == nil) {
 84         
 85         /*
 86          最常用的初始化方法
 87          nibName 表示xib文件的名字,不包括扩展名
 88          nibBundle 制定在那个文件束中搜索制定的nib文件,如在主目录下,则可以直接用nil
 89          */
 90         self.thirdViewController = [[[TWFXThirdViewController alloc] initWithNibName:@"TWFXThirdViewController" bundle:nil]autorelease] ;
 91         
 92     }
 93     
 94     //视图切换的动画效果
 95     self.thirdViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
 96     
 97     void(^task)() = ^{
 98         
 99         NSLog(@"2self: %@",self);
100         NSLog(@"2go ed%@",self.presentedViewController);
101         NSLog(@"2go ing%@",self.presentingViewController);
102         //  NSLog(@"go par%@",self.parentViewController);
103         printf("\n\n");
104     };
105     // task = ^(){};
106     
107     // task();//跳转前没意义
108     
109     
110     /*
111      completion是一个回调,当 当前视图(这里是TWFXViewController) 的viewDidDisear调用后,该回调被调用
112      self.presentingViewController(表示上一个视图)为A视图
113      self.presentedViewController(表示下一个试图)为C视图
114      */
115     [self presentViewController:thirdViewController animated:YES completion:task];
116     
117 
118 }
119 
120 
121 @end

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值