当用户点击选项卡栏目时,我是否可以在 UITabBarController
中覆盖此操作,然后检查 UserDefault
,以决定是显示视图还是保持当前视图不变?
代码示例:
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
,则实际上阻止视图甚至到达viewDidLoad
。谢谢。