2014-09-21 39 views
0

我有應用程序的結構如下:從放卷模式VC

[root VC] tabbar -> nvc1 -> vc1 -> vc2 -> [modal formsheet] nvc2 -> vc3

我要的是放鬆從vc3vc2。基本上vc2模態地呈現nvc2控制器。

我記錄的電話到viewControllerForUnwindSegueAction:fromViewController:withSender鏈:

  1. vc3電話nvc2
  2. nvc2電話tabbar

因此,所有我看到的是平倉機制橫貫只向上,而是原來的控制器贈送nvc2 - vc2tabbar > nvc1

如何解決這個問題?

回答

0

與我以前見過的其他實現不同,canPerformUnwindSegueAction無法可靠地用於查找容器控制器包含其他容器控制器的層次結構中的目標控制器。

因此,另外我使用viewControllerForUnwindSegueAction:來鑽探尋找目標控制器的道路。

值得注意的是,它與iOS 8.0相關。即使不詢問tabbar,iOS 7.1也能快速找到目標VC。

- (UIViewController*)viewControllerForUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender { 
    for(UIViewController* vc in self.viewControllers) { 
     // check if controller itself handles unwinding 
     if([vc canPerformUnwindSegueAction:action fromViewController:fromViewController withSender:sender]) { 
      return vc; 
     } 

     // check if any child controller wants to handle this 
     UIViewController* childVC = [vc viewControllerForUnwindSegueAction:action fromViewController:fromViewController withSender:sender]; 

     if(childVC) { 
      return childVC; 
     } 
    } 

    return [super viewControllerForUnwindSegueAction:action fromViewController:fromViewController withSender:sender]; 
}