How to remember last selected tab in UITabBarController?

前端 未结 6 1632
小鲜肉
小鲜肉 2021-02-08 04:30

I\'m trying to make my app remember which tab was last being viewed before the app quit, so that the app opens up to the same tab when it is next launched. This is the functiona

6条回答
  •  星月不相逢
    2021-02-08 05:04

    UPDATE

    In the UITabBarControllerDelegate's Delegate, overwrite
    

    Objective C

    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
    {
    NSLog(@"%lu",self.tabBarController.selectedIndex);
    return YES;
    }
    
    In this delegate method you will get last selected index.
    

    Swift 3.2

    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool
    {
        print("%i",tabBarController.selectedIndex)
        return true
    }
    

提交回复
热议问题