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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM