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
复制代码

 

posted @   jevan  阅读(355)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示