如何获得父导航控制器

时间:2023-01-23 14:59:44

In my AppDelegate, I have a main NavigationController that is a "drawer controller" from a third party framework. In there, I have some more controllers, and in my pageTabBarController I a PostsViewController for each page, and that PostsViewController contains a tableview. My goal is to navigate the user to a new controller when he taps a cell in that tableview.

在我的AppDelegate中,我有一个主NavigationController,它是来自第三方框架的“抽屉控制器”。在那里,我有一些更多的控制器,在我的pageTabBarController中,每个页面都有一个PostsViewController,而PostsViewController包含一个tableview。我的目标是在用户点击该桌面视图中的单元格时将用户导航到新控制器。

Check out the AppDelegate.swift setup:

查看AppDelegate.swift设置:

var viewControllers = [NavigationController]()

for name in categories {
    let navTmp = NavigationController(rootViewController: 
    PostsViewController(category: name))
    navTmp.navigationBar.isHidden = true
    viewControllers.append(navTmp)
}

let pageTabBarController = AppPageTabBarController(viewControllers: viewControllers)

let toolbarController = AppToolbarController(rootViewController: pageTabBarController)
let menuMainController = MenuViewController()
let drawerController = AppNavigationDrawerController(rootViewController: toolbarController, leftViewController: menuMainController)

window = UIWindow(frame: Screen.bounds)
window!.rootViewController = drawerController
window!.makeKeyAndVisible()

I believe that I will need the parent navigation controller to do this. Bear with me, I am new to swift. But again, my goal is to navigate the user to a new controller when he taps a cell.

我相信我需要父导航控制器才能做到这一点。忍受我,我是新手。但同样,我的目标是在用户点击一个单元格时将用户导航到新的控制器。

Edit: Looking back at this, it looks like I need to make that controller class embedded in a navigation controller, and hook one up to each PostsViewController

编辑:回头看看,看起来我需要将该控制器类嵌入到导航控制器中,并将一个挂钩到每个PostsViewController

1 个解决方案

#1


1  

Seems you're using CosmicMind's Material. So you have to put your code which navigating the view controller in the tableView delegate in a specific UIViewController class, not inside the AppDelegate.

好像你正在使用CosmicMind的材料。因此,您必须将在视图控制器中导航的代码放在特定的UIViewController类中的tableView委托中,而不是放在AppDelegate中。

#1


1  

Seems you're using CosmicMind's Material. So you have to put your code which navigating the view controller in the tableView delegate in a specific UIViewController class, not inside the AppDelegate.

好像你正在使用CosmicMind的材料。因此,您必须将在视图控制器中导航的代码放在特定的UIViewController类中的tableView委托中,而不是放在AppDelegate中。