【发布时间】:2017-06-14 22:56:25
【问题描述】:
出于这个问题的目的,我展示了我的视图层次结构的精简版本。我的应用程序包含一个 UITabBarController 作为基础。每个选项卡最顶层的视图控制器是一个导航控制器,并且每个控制器都嵌入了视图控制器。
让我们选择第一个标签。
UITabBarController -> UINavigationController -> UITableViewController -> UIViewController
假设UITableViewController 实例是某种列表,UIViewController 是详细视图。当用户点击列表中的某个项目时,它会将您带到详细视图。当发生这种情况时,我将UIViewController 的hidesBottomBarWhenPushed 属性设置为true,这样当用户在详细视图中时,底部的标签栏就会隐藏。
我的应用收到推送通知。当点击它们时,它应该直接打开到详细视图中。我可以让它导航到那里。但问题是底部的标签栏仍然可见!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
window = UIWindow(frame: UIScreen.main.bounds)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController
if openingFromPush {
let firstNavigationController = storyboard.instantiateViewController(withIdentifier: "FirstNavigationController") as! UINavigationController
let tableViewController = storyboard.instantiateViewController(withIdentifier: "TableViewController") as! TableViewController
let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
viewController.hidesBottomBarWhenPushed = true
firstNavigationController.viewControllers = [tableViewController, viewController]
tabBarController.viewControllers?[0] = firstNavigationController
// tabBarController.tabBar.isHidden = true
window?.rootViewController = tabBarController
} else {
window?.rootViewController = tabBarController
}
window?.makeKeyAndVisible()
return true
}
我在实例化视图控制器时将相同的hidesBottomBarWhenPushed 属性设置为true,但这似乎没有任何效果。我什至尝试像tabBarController.tabBar.isHidden = true 这样直接隐藏标签栏,但这也没有任何作用。
我不知道如何解决这个问题。任何帮助将不胜感激。
如果有帮助,我还附上了一个示例 Xcode 项目 here。
【问题讨论】:
标签: ios swift uiviewcontroller uinavigationcontroller uitabbarcontroller