2010-11-22 47 views
3

我有一个UINavigationController的应用程序,它包含一个根UIViewController子类(PagingViewController),它管理和充当水平分页UIScrollView的代理。在这个UIScrollView的每个页面上,都有一个垂直滚动的UITableView,每个UITableView都由它自己的UIViewController子类(PageViewController)管理。它看起来是这样的......嵌套的UIViewController需要推到根UINavigationController

UINavigationController 
    PagingViewController (root VC of navigation controller) 
    PageViewController (instance 1) 
    PageViewController (instance 2) 
    PageViewController (instance 3) 

    HowToPushThisViewController (this is what I'd like to push onto the current root, PagingViewController, from one of its sub view controllers) 

我希望做的是,在didSelectRowAtIndexPath方法:在PageViewController(UITableView的委托)的方法,推动了新的UIViewController到UINavigationController的(在PagingViewController的顶部)。

问题是PageViewController的navigationController属性为零,所以我不能将它推到那里。我认为这是零,因为它不直接在UINavigationController的堆栈上,但包含的PagingViewController,其中在堆栈上。我尝试在将每个PageViewController的navigationController属性添加到PagingScrollView之前设置它的navigationController属性,但它似乎是只读的(UINavigationController如何设置它自己?)。我觉得嵌套的UIViewControllers是健全的体系结构(每个人都需要管理和充当其视图的委托),并且想要从子控制器中推导导航是合理的,所以我不确定最好的练习从嵌套控制器访问和推送。希望有一些简单的东西可以忽略,可以访问并推送到根naviagtion控制器。

回答

2

合乎逻辑的事情是设置页面视图控制器的parentViewController属性,但是,它也是只读的。 Apple不鼓励视图控制器的自定义层次结构(除了带标签栏,导航和分割视图控制器的支持层次结构外)。

就你的情况而言,我将在PageViewController类上定义一个自定义parentVC属性,PagingViewController在实例化其子级时将其设置为自身。然后PageViewController可以通过

self.parentVC.navigationController 
+0

或者,覆盖`-parentViewController`。这似乎允许一些UIViewController魔术工作,包括(我认为)-navigationController。伊西,不过! – 2010-11-23 04:33:47

相关问题