[英]Dismiss and Pop a view controller
我想在視圖控制器堆棧上返回兩個級別。 我按順序有三個segue:Show,Show,Present Modally。 有一個導航控制器正在使用中。 從我的第四個觀點來看,我想回到第二個視圖。 我試過使用self.presentingViewController?.presentingViewController?.navigationController?.popViewControllerAnimated(false);
和
self.presentingViewController?.presentingViewController?.dismissViewControllerAnimated(false, completion: nil);
第二個只有當第二個和第三個被稱為“模態呈現”時才有效。 如何讓他們與解雇和流行音樂一起工作?
在彈出其他兩個之前嘗試解除顯示的視圖控制器:
func dismissThenDoublePop() {
// Get the presenting/previous view
let previousView = self.presentingViewController as UINavigationController
// Dismiss the current view controller then pop the others
// upon completion
self.dismissViewControllerAnimated(true, completion: {
// Get an array of the current view controllers on your nav stack
let viewControllers: [UIViewController] = previousView.viewControllers as [UIViewController];
// Then either pop two view controllers, i.e. pop
// to viewControllers[viewControllers.count - 2], or
// pop to the second view controller in the nav stack,
// i.e. viewControllers[1]. (In this case I've used the
// first option.)
self.navigationController!.popToViewController(viewControllers[viewControllers.count - 2], animated: true);
});
}
你可以使用這種技術
https://stackoverflow.com/a/15839298/1153100
簡單干凈(Unwind segues)
@IBAction func unwindAction(segue: UIStoryboardSegue) {
}
你喜歡這個。
self.navigationController?.popViewControllerAnimated(true)
只需調用dismissViewControllerAnimated。它將自動關閉所有視圖控制器,包括呈現的模型viewcontroller。
目標 - C.
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
迅速
self.navigationController?.dismissViewControllerAnimated(false, completion: nil);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.