gpt4 book ai didi

swift - 打开一个不是 Root View 的 View ,并将 tabbarcontroller 保留在 Root View 中(swift)

转载 作者:搜寻专家 更新时间:2023-11-01 07:26:58 26 4
gpt4 key购买 nike

大家好,我有一个应用程序,其 View 组织如下图所示:

观点: enter image description here

当用户打开附件时,我的应用程序必须打开 View B(从图片中看)(我有另一个问题 Open specific view when user opens an attachment 我已经找到了这个问题的答案)。我已经这样做了,我的问题是当我打开 View B 时,标签栏不存在。

有没有一种方法可以让我在打开 View B 时看到作为 Root View 一部分的标签栏?

更新:下面是我用来从 AppDelegate.swift 文件打开 View 的代码:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("AddComment") as! AddCommentViewController
window?.rootViewController = vc
}

最佳答案

刚看到你更新的帖子。为了使其工作,必须满足以下条件:

  1. window?.rootViewController 是一个 UITabBarController
  2. 标签栏中 indexOfNavigationViewControllerInTabBar 处的 View Controller 是 UINavigationViewController。

如果是,那么做:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
let indexOfNavigationViewControllerInTabBar = 0 // Set yourself
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("AddComment") as! AddCommentViewController
let tabBarController = window?.rootViewController as! UITabBarController
let navigationController = tabBarController.viewControllers![indexOfNavigationViewControllerInTabBar] as! UINavigationController
navigationController.setViewControllers([vc], animated: true)
tabBarController.selectedIndex = indexOfNavigationViewControllerInTabBar
}

关于swift - 打开一个不是 Root View 的 View ,并将 tabbarcontroller 保留在 Root View 中(swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35445017/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com