2014-12-17 2 views
3

내보기 컨트롤러 스택에서 두 수준으로 돌아가고 싶습니다. 나는이 순서대로 세 가지 단편을 가지고있다 : 쇼, 쇼, 현재의 모덜. 사용중인 탐색 컨트롤러가 있습니다. 내 4 번째보기에서 두 번째보기로 돌아가고 싶습니다. 나는 self.presentingViewController?.presentingViewController?.navigationController?.popViewControllerAnimated(false);보기 컨트롤러 닫기 및 닫기

self.presentingViewController?.presentingViewController?.dismissViewControllerAnimated(false, completion: nil);

두 번째는 경우에만 작동을 사용하여 시도 2와 '현재의 모달'등 3 segues. 나는 그들에게 해고와 갑자기 일하도록 어떻게 할 수 있습니까? 다른 두 터지는 전에 발표 뷰 컨트롤러를 기각

+0

보인다. –

+0

대신 긴장을 풀 수 있습니다. – rdelmar

+0

@rdelmar 스토리 보드를 사용하는 경우에만 긴장을 풀 수 있습니다. –

답변

5

시도 :

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); 

    }); 
} 
+0

'let viewController : ...'로 시작하는 줄에 도착하고 "치명적인 오류 : 선택 값을 언 래핑하는 동안 예기치 않게 nil이 발견되었습니다" – Ricca

+0

@Ricca 네, 맞습니다. 네비게이션 컨트롤러가 제시된보기에서 nil입니다. 제어 장치. 지금 대안을 찾고 있습니다. –

+0

@Ricca 그래, dismissView 블록 전에 UINavigationController로 이전보기를 얻기 위해 내 대답을 업데이 트했습니다. 이 코드를 테스트 해본 결과 나에게 도움이되었습니다. –

-1

는이처럼 사용합니다.

self.navigationController?.popViewControllerAnimated(true) 
0

그냥 가 .IT가 자동으로 모든 뷰 컨트롤러 제시를 포함하여 기각한다을 dismissViewControllerAnimated 전화 심플하고 깨끗한 모델 viewcontroller.

목적 - 당신이 다른 두 터지는 전에 발표 뷰 컨트롤러를 기각해야 할 것 같은 C

[self.navigationController dismissViewControllerAnimated:YES completion:nil]; 

스위프트

self.navigationController?.dismissViewControllerAnimated(false, completion: nil);