【问题标题】:How to deeplink to a UIViewController accessed from a UIViewController in a UINavigationController in a UITabBarViewController?如何在 UITabBarViewController 中的 UINavigationController 中深度链接到从 UIViewController 访问的 UIViewController?
【发布时间】:2017-04-04 16:43:22
【问题描述】:

我需要深度链接到一个 UIViewController,该 UIViewController 可以从另一个 UIViewController 访问,该 UIViewController 位于 UINavigationViewController 中,它本身是 UITableViewController 中的一个选项卡。

基本上是这样的

UITabBarViewController -> (每个标签) UINavigationController -> UIViewController -> (Press UIBarButtonItem) -> TheViewControllerIWant

由于我正在处理的项目的限制,这一切都是在我的 AppDelegate 中以编程方式创建的。我无法使用 Storyboards 来解决这个问题。

这是我现有的代码。它让我进入 ViewController,但没有让我导航回选项卡中的 ViewController

- (BOOL) application: (UIApplication * ) application openURL: (NSURL *) url sourceApplication: (NSString *) sourceApplication annotation: (id) annotation {

    if ([url.scheme isEqualToString: @"myApp"]) {

        if ([url.host isEqualToString: @"account"])
        {
            self.window.rootViewController = [[EditAccountViewController alloc] init];
        }
}

我也尝试过这个作为开始,但无法从 TabBar 中的一个向前导航到下一个 ViewController:

- (BOOL) application: (UIApplication * ) application openURL: (NSURL *) url sourceApplication: (NSString *) sourceApplication annotation: (id) annotation {

    if ([url.scheme isEqualToString: @"myApp"]) {

        if ([url.host isEqualToString: @"account"])
        {
            [_tabBarController setSelectedIndex:0];
            self.window.rootViewController = _tabBarController;
        }
    }
}

我该如何做到这一点

【问题讨论】:

    标签: ios objective-c uinavigationcontroller uitabbarcontroller deep-linking


    【解决方案1】:

    那么你需要手动触发所有动作......

    因此,您需要先选择 TabBarController 上的第一个选项卡 然后你需要获取第一个 Tab 的 UIViewController 并在 Navigation Controller 中推送目标 ViewController...

    [_tabBarController setSelectedIndex:0];
    UIViewController *myVC = self.tabBarController.viewControllers.firstObject;
    UIViewController *destinationVC = [[UIViewController alloc] initWithNibName:@"vc.nib" bundle:[NSBundle mainBundle]];
    [myVC.navigationController pushViewController:destinationVC animated:YES];
    

    【讨论】:

    • 如果是tabbar中的2nd 3rd etc对象,会有对应的.secondObject .thirdObject etc调用vcs吗?
    • 如果我需要更深一层并在上述答案之后推动另一个 VC,我该怎么做?
    • 如果你想让导航栈保持特定的顺序,你必须在下一次推送之后在栈上推送一个新的 viewController。如果您不关心堆栈,那么您可以初始化最终目标视图控制器并将其作为导航堆栈中的第一个 VC 推送。至于您的其他问题,self.tabBarController.viewControllersNSArray,因此您将引用其他 ViewController,例如 `[self.tabBarController.viewControllers objectAtIndex:2];' , 3 , 4 等等......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    • 2015-06-10
    • 1970-01-01
    • 2012-02-07
    相关资源
    最近更新 更多