ios學習:頁面跳轉(present)

來源:互聯網
上載者:User

標籤:

////  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

 

ios學習:頁面跳轉(present)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.