ios学习:页面跳转(present)

时间:2023-03-09 14:38:26
ios学习:页面跳转(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视图跳转到B视图,那么A表示当前视图,B表示将要跳转到视图
多视图跳转可以理解为有两部分:从A跳到B, B 返回 A.注意,是返回,不是重新发起跳转
这里是第二阶段:从B返回A self.presentingViewController 在跳转发生后有效,表示B试图的上一个视图,在这里为A视图
self.presentedViewController 在跳转发生后有效,表示B视图的下一个视图,在这里为nil,以为并没有发生跳转
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(); //跳转完成后调用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();//跳转前没意义 /*
completion是一个回调,当 当前视图(这里是TWFXViewController) 的viewDidDisear调用后,该回调被调用
self.presentingViewController(表示上一个视图)为A视图
self.presentedViewController(表示下一个试图)为C视图
*/
[self presentViewController:thirdViewController animated:YES completion:task]; } @end