如何隐藏标签栏中的某些 View Controller ?
例如,我的选项卡栏有 3 个 View Controller ,但我的应用程序有两种类型的用户:
- user 1 can only access one of those view controllers
- user 2 can access the 3 view controllers
如何隐藏某些 View Controller ,知道用户是谁?
我有这个代码
if user1 == 'admin'
{
let tabone = EstadisticasViewController()
let tab1 = UITabBarItem(title: "Estadisticas", image: nil, selectedImage: nil)
tabone.tabBarItem = tab1
self.viewControllers = [tabone]
}
但结果我有一个黑色的 View ,在我的 Storyboard View “estadísticas”中有按钮、图像和文本。
最佳答案
我认为这很容易 首先您需要添加所有选项卡栏项目, 然后根据您的用户角色隐藏标签栏索引,如下所示..
if user1 == 'admin'
{
//Show All Tabs
}
else
{
let indexToRemove = 3
if let tabBarController = self.tabBarController {
if indexToRemove < tabBarController.viewControllers?.count {
var viewControllers = tabBarController.viewControllers
viewControllers?.remove(at: indexToRemove)
tabBarController.viewControllers = viewControllers
}
}
}
关于ios - 如何在标签栏 Controller 中隐藏 View Controller swift?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48966195/