如何使用选项卡和导航控制器实例化视图控制器以进行深度链接?

How to instantiate a view controller with tab and nav controller for deep linking?

我正在为我的应用实施深度 linking,但无法正确实例化我的应用。对于我的应用程序 link,它正在打开博客 post 的详细信息页面,因此我将其实例化如下:

var controller = PostDetailController()

问题是底部没有导航 header 或标签栏。如何从头开始正确启动我的应用程序然后加载我的 PostDetailController?

下面是我的故事板的样子,我正在尝试 link 直接到我的 "Post Detail Controller",但是它后面有所有以前的控制器,我该怎么做?

您可以通过多种不同的方式来实现这一点。假设您从应用委托的 openURL: 方法开始,这里是一种方法的高级视图。

  1. openURL:方法中,从url中解析出需要的参数并将其存储在全局变量中。
  2. 子类化您的 UITabBarController 并创建一个函数来处理深度 link。此函数应评估应用程序委托中设置的全局变量并确定需要显示哪个选项卡和视图。

例如:

        // Check for deep link global var

        if (myGlobalVar==1){
            //Instantiate the destination view (the view you want the deep link to show)
            DetailViewController *detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"myDetailView"];

            //set any vars need in the destination view

            //Push the detail View to stack of the to be seleceted Tab
            [[self.viewControllers objectAtIndex:myTABINDEX] pushViewController:detailViewController animated:NO];

            //select the tab to the destination view
            [self setSelectedIndex:myTABINDEX];

        }