是否有可能当用户点击一个标签栏项目时,我可以在 UITabBarController 中覆盖它,然后我检查一个 UserDefault ,然后决定我是否显示 View 或 return 并且他们停留在当前 View ?
应该是这样的:
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
if item.image == UIImage(named: "TabProfile")
{
// Profile tab selected
if !loginController.isUserLogged()
{
// Not logged in...
showLoginView()
// Following line doesn't work...
tabBarController?.selectedIndex = selectedIndex
}
}
}
如果可能,我想执行此检查,如果 false 则实际上阻止 View 甚至到达 viewDidLoad 。
谢谢。
Best Answer-推荐答案 strong>
我猜你需要
func tabBarController(_ tabBarController: UITabBarController,
shouldSelect viewController: UIViewController) -> Bool {
if let ind = tabBarController.viewControllers!.index(of:viewController) , ind == 2 { // suppose profile is 2
//
if userNotLogged {
// present modal login view
return false
}
}
return true
}
关于ios - Swift 4 - 如何覆盖标签栏将打开 View Controller ,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/54138246/
|