How to remember last selected tab in UITabBarController?

前端 未结 6 1636
小鲜肉
小鲜肉 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 04:57

    I subclassed TabBarController and:

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        self.selectedIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"activeTab"];
    }
    
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
    
        [[NSUserDefaults standardUserDefaults] setInteger: self.selectedIndex
                 forKey:@"activeTab"];
    }
    

提交回复
热议问题