頁面跳轉(zhuǎn)(present)

//

//? TWFXSecondViewController.m

//? DemoMultiView

//

//? Created by Lion User on 12-12-24.

//? Copyright (c) 2012年 Lion User. All rights reserved.

//

#import "TWFXSecondViewController.h"

#import "TWFXThirdViewController.h"

@interface TWFXSecondViewController ()

@end

@implementation TWFXSecondViewController

@synthesize thirdViewController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {

// Custom initialization

}

return self;

}

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view from its nib.

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

/*

多視圖切換,如果是從A視圖跳轉(zhuǎn)到B視圖,那么A表示當前視圖,B表示將要跳轉(zhuǎn)到視圖

多視圖跳轉(zhuǎn)可以理解為有兩部分:從A跳到B, B 返回 A.注意,是返回,不是重新發(fā)起跳轉(zhuǎn)

這里是第二階段:從B返回A

self.presentingViewController 在跳轉(zhuǎn)發(fā)生后有效,表示B試圖的上一個視圖,在這里為A視圖

self.presentedViewController 在跳轉(zhuǎn)發(fā)生后有效,表示B視圖的下一個視圖,在這里為nil,以為并沒有發(fā)生跳轉(zhuǎn)

self.parentViewController表示B的父試圖,也為nil

*/

-(IBAction)btnClicGoBack:(UIButton *)sender{

void(^task)() = ^{

NSLog(@"2self: %@",self);

NSLog(@"2back ed%@",self.presentedViewController);

NSLog(@"2back ing%@",self.presentingViewController);

//? NSLog(@"back par%@",self.parentViewController);

printf("\n\n");

};

// task();

//跳轉(zhuǎn)完成后調(diào)用completion,此時,當前視圖已被銷毀,self.presentedViewController self.presentingViewController都為nil

[self dismissViewControllerAnimated:YES completion:nil];

task();//此時,當前視圖還沒被銷毀,self.presentingViewController 表示上一個視圖

}

- (IBAction)btnClickTraToFirst:(UIButton *)sender {

}

/*

這里表示從B視圖跳到C視圖

*/

- (IBAction)btnClickTra:(UIButton *)sender {

if (self.thirdViewController == nil) {

/*

最常用的初始化方法

nibName 表示xib文件的名字,不包括擴展名

nibBundle 制定在那個文件束中搜索制定的nib文件,如在主目錄下,則可以直接用nil

*/

self.thirdViewController = [[[TWFXThirdViewController alloc] initWithNibName:@"TWFXThirdViewController" bundle:nil]autorelease] ;

}

//視圖切換的動畫效果

self.thirdViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

void(^task)() = ^{

NSLog(@"2self: %@",self);

NSLog(@"2go ed%@",self.presentedViewController);

NSLog(@"2go ing%@",self.presentingViewController);

//? NSLog(@"go par%@",self.parentViewController);

printf("\n\n");

};

// task = ^(){};

// task();//跳轉(zhuǎn)前沒意義

/*

completion是一個回調(diào),當 當前視圖(這里是TWFXViewController) 的viewDidDisear調(diào)用后,該回調(diào)被調(diào)用

self.presentingViewController(表示上一個視圖)為A視圖

self.presentedViewController(表示下一個試圖)為C視圖

*/

[self presentViewController:thirdViewController animated:YES completion:task];

}

@end

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容