Prevent tabbar from changing tab at specific index - IOS

不羁的心 提交于 2019-12-01 02:52:41
Kasaname
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    if (tabBarController.selectedIndex == 0) {

    } else if (tabBarController.selectedIndex == 1) {

    } else if (tabBarController.selectedIndex == 2) {

    }
}

why dont u use this delegate Use this delegate it will work i suppose

Valeriy

This is how you can stop/prevent Tabbar items to switch your tab on tabbar item click

For Swift 3.0

Make sure you have implemented UITabBarControllerDelegate and set UITabbarController's delegate to self

then override this delegate in your controller

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {

    if viewController == tabBarController.viewControllers?[2] {
        return false
    } else {
        return true
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!