//
//? 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表示當(dāng)前視圖,B表示將要跳轉(zhuǎn)到視圖
多視圖跳轉(zhuǎn)可以理解為有兩部分:從A跳到B, B 返回 A.注意,是返回,不是重新發(fā)起跳轉(zhuǎn)
這里是第二階段:從B返回A
self.presentingViewController 在跳轉(zhuǎn)發(fā)生后有效,表示B試圖的上一個(gè)視圖,在這里為A視圖
self.presentedViewController 在跳轉(zhuǎn)發(fā)生后有效,表示B視圖的下一個(gè)視圖,在這里為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,此時(shí),當(dāng)前視圖已被銷毀,self.presentedViewController self.presentingViewController都為nil
[self dismissViewControllerAnimated:YES completion:nil];
task();//此時(shí),當(dāng)前視圖還沒被銷毀,self.presentingViewController 表示上一個(gè)視圖
}
- (IBAction)btnClickTraToFirst:(UIButton *)sender {
}
/*
這里表示從B視圖跳到C視圖
*/
- (IBAction)btnClickTra:(UIButton *)sender {
if (self.thirdViewController == nil) {
/*
最常用的初始化方法
nibName 表示xib文件的名字,不包括擴(kuò)展名
nibBundle 制定在那個(gè)文件束中搜索制定的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是一個(gè)回調(diào),當(dāng) 當(dāng)前視圖(這里是TWFXViewController) 的viewDidDisear調(diào)用后,該回調(diào)被調(diào)用
self.presentingViewController(表示上一個(gè)視圖)為A視圖
self.presentedViewController(表示下一個(gè)試圖)為C視圖
*/
[self presentViewController:thirdViewController animated:YES completion:task];
}
@end