0

아래쪽 탭으로 탐색 할 수있는 탐색 기반 앱을 만들고 각 탭에는 자체 탐색 스택이 있습니다. 대부분의 부품이 예상대로 작동하지만 하나의 특정 탭이 예기치 않게 작동합니다. 무슨 일performSegue는 다음 뷰 컨트롤러를 원하지 않는 뷰 계층 구조로 푸시합니다.

은 다음과 같습니다

여러 뷰 컨트롤러를 탐색 한 후,의 말 [A] [B] [C] 및 [D], 다음 컨트롤러 [E]가 갑자기 탐색 스택에서 이동 할 수 있습니다. 보기가 모달로 표시되는 것처럼 보이고 탐색 스택이 이렇게 보입니다.

(lldb) po [[[UIWindow keyWindow] rootViewController] _printHierarchy] 

<MyApp.CRTabBarController 0x112026800>, state: disappeared, view: <UILayoutContainerView 0x111e1fa00> not in the window 
    | <UINavigationController 0x112027a00>, state: disappeared, view: <UILayoutContainerView 0x111e23f50> not in the window 
    | | <MyApp.X1_ViewController 0x111d12490>, state: disappeared, view: <UIView 0x111e32d70> not in the window 
    | | | <MyApp.InsideX1_ViewController 0x112096200>, state: disappeared, view: <UIView 0x111e35d90> not in the window 
    | <UINavigationController 0x11200aa00>, state: disappeared, view: (view not loaded) 
    | | <MyApp.X2_ViewController 0x111d22360>, state: disappeared, view: (view not loaded) 
    | <UINavigationController 0x11205a200>, state: disappeared, view: (view not loaded) 
    | | <MyApp.X3_Controller 0x11205a800>, state: disappeared, view: (view not loaded) 
    | <UINavigationController 0x112059600>, state: disappeared, view: (view not loaded) 
    | | <MyApp.X4_ViewController 0x111e0cea0>, state: disappeared, view: (view not loaded) 
    | <UINavigationController 0x112058e00>, state: disappeared, view: <UILayoutContainerView 0x111d50370> not in the window 
    | | <MyApp.A_ViewController 0x111d25f70>, state: disappeared, view: <UIView 0x116e0ad90> not in the window 
    | | | <MyApp.PageViewController 0x112891400>, state: disappeared, view: <_UIPageViewControllerContentView 0x113feb0a0> not in the window 
    | | | | <MyApp.InnerPageViewController 0x111ee3bf0>, state: disappeared, view: <UIView 0x111e6e000> not in the window 
    | | <MyApp.B_ViewController 0x113ee8280>, state: disappeared, view: <UIView 0x116e37cf0> not in the window 
    | | <MyApp.C_Controller 0x118f06f10>, state: disappeared, view: <UIView 0x113ee46f0> not in the window 
    | | <MyApp.D_ViewController 0x116e5f580>, state: disappeared, view: <UIView 0x118f2fe70> not in the window 
    + <E_ViewController 0x116ecff30>, state: appeared, view: <UIView 0x111ee43f0>, presented with: <_UIFullscreenPresentationController 0x116e13420> 

위에서 네 개의 네비게이션 컨트롤러는 여기에 관심이없는 비활성 탭입니다. 마지막 탭의 탐색에서 A_ to D_ - ViewController's을 볼 수 있습니다. 그런 다음 E_ViewController이 다른 탐색 계층 구조에 있는데, 이것이 여기서 문제입니다.

코드는 꽤 똑 바릅니다. D_ViewController은 이와 같이 performSegue을 호출합니다.

self.performSegue(withIdentifier: "goto_E", sender: self) 

Segue 설정도 꽤 정상적이라고 생각합니다. 그것은 단지 id와 "Show"를 스타일로 지정합니다. SegueD_ViewController에서 E_ViewController으로 연결되어 있으므로 performSegue's 식별자 arg로 참조 할 수 있습니다.

enter image description here

아무도 경험이 종류 있었나요? 가능한 이유에 대한 추측은?

+0

D에서 E까지의 세그가 체인의 다른 것들과 같습니까? B에서 C 또는 C에서 D로 말합니까? –

+0

네, 모두 같습니다. 나는 segues를 클릭하여 시각적으로 비교했으며 식별자를 제외하고는 아무것도 변경하지 않았습니다. –

+0

그리고 그들은 B_ViewController를 C_ViewController로, C_ViewController를 D_ViewController에 동일한 방식으로 사용합니까? –

답변

0

// SEGUE를 제거하고

extension UIViewController { 

    class func instantiate(fromStoryboard name: String, id: String) -> Self? { 
     return instantiateHelper(fromStoryboard: name, id: id) 
    } 

    private class func instantiateHelper<T>(fromStoryboard name: String, id: String) -> T? { 
     let storyboard = UIStoryboard(name: name, bundle: nil) 
     let controller = storyboard.instantiateViewController(withIdentifier: id) as? T 
     return controller 
    } 
} 

사용을 인스턴스화 : - 코멘트에 대한

guard let vc = ViewController.instantiate(fromStoryboard: "Main", id: "ViewController") else { return } 
self.navigationController?.pushViewController(vc, animated: true) 
+0

왜? segue를 제거하고 대신 인스턴스를 사용하는 이유는 무엇입니까? 그것은 모든 일을 다 끝내고 사용하지 않았습니까? –

+0

좋은 해결 방법처럼 보입니다. 요점은 Storyboard에서 VC를 잡아 내서 탐색 컨트롤러에 직접 밀어 넣는 것입니다. 맞습니까? 내가 한 번 기회를 줘 보자. –

+0

@UpholderOfTruth 많은 시간이 제대로 작동하지 않습니다. 따라서 인스턴스화하는 것이 좋습니다. –

0

감사합니다,하지만 난 나 자신에 의해 그것을 해결했습니다. 말하기가 당황 스럽지만 그 이유는 꽤 바보 같았습니다. 전화 번호 performSegue 바로 전에 popViewController을 호출하고있었습니다.

이 팝 콜은 내보기 구조가 변경 되었기 때문에 거기에 있었고 분리 된 위치에 작성 되었기 때문에 눈치 채기가 어려웠습니다.

직접적인 대답은 아니지만 Storyboard에서 직접 인스턴스화하는 방법이 문제를 명확히하는 데 유용했습니다. 고마워, Pratyush.

하지만 segue 결과를 끌어 오기 전에보기 컨트롤러가 터지는 것이 이러한 종류의 동작으로 완전히 예상하지 않았습니다. 다른 사람의 문제를 암시 할 수 있기를 바랍니다.

관련 문제