【发布时间】:2018-03-07 17:41:14
【问题描述】:
我正在尝试为我的 iPhone“选项卡式应用程序”创建一个导航,该导航将由(显然)UITabBarController 和 SWRevealViewController 组成,用于显示侧面菜单。
我的应用程序中的所有视图必须同时显示UITabBarController 和UINavigationBar,但是,出现在左侧菜单中的链接(由SWRevealViewController 处理)不得出现在UITabBarController。
我的左侧菜单链接是这样处理的:
import UIKit
class MenuTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.clearsSelectionOnViewWillAppear = false
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedIndex = (indexPath as NSIndexPath).row + 1 // hardcoded for time being
let tabBarController = revealViewController().frontViewController as! UITabBarController
let navController = tabBarController.viewControllers![selectedIndex] as! UINavigationController
navController.popToRootViewController(animated: true)
tabBarController.selectedIndex = selectedIndex
revealViewController().pushFrontViewController(tabBarController, animated: false)
}
}
现在,我尝试删除我不想在UITabBarController 中显示的视图之一的链接,如下所示:
import UIKit
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let index = 2 // hardcoded for time being
viewControllers?.remove(at: index)
}
}
但如果我现在点击左侧菜单中的关联链接,我会收到 NSRangeException index 2 beyond bounds [0 .. 1] 错误(当然,因为我从 UITabBarController 中删除了特定的 tabBarItem)。
我的问题是:我怎样才能“隐藏”UITabBarController 中的项目,但仍然能够从我的侧菜单中引用它(并打开它)?
【问题讨论】:
-
所以...你有一个带有
ABC标签的标签栏控制器...当前标签是B...你还有一个菜单列表DEFG...用户在菜单上点击E...应该发生什么?当前标签B被E替换?或者A-B-C标签变成A-B-C-E? -
假设我有
ABCDE视图。我只想在我的 TabBar 中显示ABC和DE在我的侧边菜单中。但是,D和E在打开后都应该显示 TabBar。在我的故事板中,所有视图都连接到我的 TabBar 控制器,以便 TabBar 在它们上可见,也许这首先是错误的方法?
标签: ios swift uitabbarcontroller swrevealviewcontroller xcode9