簡體   English   中英

iOS:如何讓ViewController A模態地呈現B,然后直接將B取消/轉換為模態呈現的C?

[英]iOS: How can I have ViewController A present B modally and then have B dismiss/transition directly to a modally presented C?

現在,我有一個ViewController(“ A”)以模態形式呈現用戶的iPod庫(“ B”):

// This works great
- (void)selectSong { // UIBarButtonSystemItemAdd target action
    MPMediaPickerController *picker = [[MPMediaPickerController alloc] init];
    picker.delegate = self;
    [self presentViewController:picker animated:YES completion:NULL];
}

我通過委托從“ A”內部取消了模態呈現的VC“ B”:

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
    // Do stuff with selected item...

    // Set up modal transition style and then dismiss
    [mediaPicker setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [mediaPicker dismissViewControllerAnimated:YES completion:^{
        // Launch capture screen
        // DOING IT THIS WAY CLEARLY SHOWS VIEW "A" BEFORE WE SEE VIEW "C"
        // I'M LOOKING FOR A WAY I CAN DISMISS THE MODAL IPOD MUSIC PICKER
        // VIA "FLIP" DIRECTLY TO VIEW CONTROLLER "C" (WHICH DOES SOMETHING
        // WITH THE SELECTED SONG).
        [self performSegueWithIdentifier:@"captureViewController" sender:self];
    }];
}

通過這種實現,從技術上講,一切都可以工作。 我不喜歡ViewController A同時顯示B和C的方式,用戶可以在關閉B之后再顯示C之前看到ViewControllerA。我希望A顯示B,然后B直接將其釋放/轉換為C.我怎樣才能做到這一點?

*更新:還請注意,如果我將手動segue調用放在補全代碼塊之外,那么會出現有關一次顯示兩件事的錯誤。 如果我將動畫設置為“否”,則會收到另一個錯誤。

在故事板中給captureViewController一個標識符。

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
    // Do stuff with selected item...

    // Set up modal transition style and then dismiss

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"STORYBOARDNAME" bundle:nil];
    UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"captureViewController"];
    [self presentModalViewController:vc animated:NO];

    [mediaPicker setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [mediaPicker dismissViewControllerAnimated:YES completion:nil];
}

試試這個,

- (void)selectSong { // UIBarButtonSystemItemAdd target action
    MPMediaPickerController *picker = [[MPMediaPickerController alloc] init];
    picker.delegate = self;
 [self performSegueWithIdentifier:@"captureViewController" sender:self];
    }];
    [self presentViewController:picker animated:YES completion:NULL];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM