Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 543401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:32:51+00:00 2026-05-13T10:32:51+00:00

I am having problems finding any other information than the docs for how to

  • 0

I am having problems finding any other information than the docs for how to save the tab order for my UITabBarController, so that the user’s customization is saved for next app launch. I have searched online, but have been unable to find any blog posts or articles that goes through the proper code for doing this.

I realize I have to use the delegate methods for the UITabBarController (didEndCustomizingViewControllers:) but I am not sure how I best approach persistance in terms of saving the state of the order the user wants the tabs in.

Can someone post some code, point me in the right direction or perhaps you have a link for something saved? 🙂

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:32:52+00:00Added an answer on May 13, 2026 at 10:32 am

    As far as you’ve asked for some sample code I will simply post here how I dealt with the same task in my app.

    Quick intro: I was using a NIB file for storing initial UITabBarController state and to differ my tabs one from another I simply defined tag variables for UITabBarItem objects assigned to each UIViewController stuffed in my UITabBarController. To be able to accurately track last selected tab (including the ‘More’ one) I’ve implemented following methods for UITabBarControllerDelegate of my UITabBarController and UINavigationControllerDelegate of its moreNavigationController. Here they are:

    #pragma mark UINavigationControllerDelegate
    
    - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        [[NSUserDefaults standardUserDefaults] setInteger:mainTabBarController.selectedIndex forKey:@"mainTabBarControllerSelectedIndex"];
    }
    
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        [[NSUserDefaults standardUserDefaults] setInteger:mainTabBarController.selectedIndex forKey:@"mainTabBarControllerSelectedIndex"];
    }
    
    #pragma mark UITabBarControllerDelegate
    
    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
        [[NSUserDefaults standardUserDefaults] setInteger:tabBarController.selectedIndex forKey:@"mainTabBarControllerSelectedIndex"];
    }
    

    And here’s the code for saving the tabs order:

    #pragma mark UITabBarControllerDelegate
    
    - (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed {
        int count = mainTabBarController.viewControllers.count;
        NSMutableArray *savedTabsOrderArray = [[NSMutableArray alloc] initWithCapacity:count];
        for (int i = 0; i < count; i ++) {
            [savedTabsOrderArray addObject:[NSNumber numberWithInt:[[[mainTabBarController.viewControllers objectAtIndex:i] tabBarItem] tag]]];
        }
        [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithArray:savedTabsOrderArray] forKey:@"tabBarTabsOrder"];
        [savedTabsOrderArray release];
    }
    

    As you can see I’ve been storing the order of tabs’ indexes in an array in NSUserDefaults.

    On app’s launch in applicationDidFinishLaunching: method I reordered the UIViewControllers using following code:

    - (void)applicationDidFinishLaunching:(UIApplication *)application {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        mainTabBarController.delegate = self;
    
        int count = mainTabBarController.viewControllers.count;
        NSArray *savedTabsOrderArray = [[userDefaults arrayForKey:@"tabBarTabsOrder"] retain];
        if (savedTabsOrderArray.count == count) {
            BOOL needsReordering = NO;
    
            NSMutableDictionary *tabsOrderDictionary = [[NSMutableDictionary alloc] initWithCapacity:count];
            for (int i = 0; i < count; i ++) {
                NSNumber *tag = [[NSNumber alloc] initWithInt:[[[mainTabBarController.viewControllers objectAtIndex:i] tabBarItem] tag]];
                [tabsOrderDictionary setObject:[NSNumber numberWithInt:i] forKey:[tag stringValue]];
    
            if (!needsReordering && ![(NSNumber *)[savedTabsOrderArray objectAtIndex:i] isEqualToNumber:tag]) {
                    needsReordering = YES;
                }
            }
    
            if (needsReordering) {
                NSMutableArray *tabsViewControllers = [[NSMutableArray alloc] initWithCapacity:count];
                for (int i = 0; i < count; i ++) {
                    [tabsViewControllers addObject:[mainTabBarController.viewControllers objectAtIndex:
                                                    [(NSNumber *)[tabsOrderDictionary objectForKey:
                                                                  [(NSNumber *)[savedTabsOrderArray objectAtIndex:i] stringValue]] intValue]]];
                }
                [tabsOrderDictionary release];
    
                mainTabBarController.viewControllers = [NSArray arrayWithArray:tabsViewControllers];
                [tabsViewControllers release];
            }
        }
        [savedTabsOrderArray release];
    
        if ([userDefaults integerForKey:@"mainTabBarControllerSelectedIndex"]) {
            if ([userDefaults integerForKey:@"mainTabBarControllerSelectedIndex"] == 2147483647) {
                mainTabBarController.selectedViewController = mainTabBarController.moreNavigationController;
            }
            else {
                mainTabBarController.selectedIndex = [userDefaults integerForKey:@"mainTabBarControllerSelectedIndex"];
            }
        }
    
        mainTabBarController.moreNavigationController.delegate = self;
    
        [window addSubview:mainTabBarController.view];
    }
    

    It’s quite tricky and may seem strange, but don’t forget that my UITabBarController was fully created in a nib file. If you construct it programmatically you may simply do the same but following the saved order.

    P.S.: and don’t forget to synchronize NSUserDefaults when your app terminates.

    - (void)applicationWillTerminate:(UIApplication *)application {
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    

    I hope this will help. If something is not clear please do comment and ask.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.