开发者

moreNavigationController save settings

I have a tab bar in my application and it has a "More" tab because there are more th开发者_StackOverflowan five tabs.

This "More" tab is generated automatically and therefore I thought that it would all work "out of the box" but when I tried going to the "Edit" menu, substitute an icon on the bar with one in the "More" view, it was not saved next time I launced the application.

How can I let the user save this setting?


As futureelite7 said, that is the way to go. If you need help, this is how we do it:

- (void) tabBarController:(UITabBarController *)tabBarCtroller
 didEndCustomizingViewControllers:(NSArray *)viewControllers
                          changed:(BOOL)changed {
  NSUInteger count = tabBarCtroller.viewControllers.count;
  NSMutableArray *tabOrderArray = [[NSMutableArray alloc] initWithCapacity:count];

  for (UIViewController *viewController in viewControllers) {
    NSInteger tag = viewController.tabBarItem.tag;
    [tabOrderArray addObject:[NSNumber numberWithInteger:tag]];
  }

  [[NSUserDefaults standardUserDefaults] setObject:tabOrderArray forKey:@"savedTabOrder"];
  [[NSUserDefaults standardUserDefaults] synchronize];

  [tabOrderArray release];
}

And in your applicationDidFinishLaunching

NSArray *initialViewControllers =
    [NSArray arrayWithArray:self.tabBarController.viewControllers];
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  NSArray *tabBarOrder = [defaults arrayForKey:@"savedTabOrder"];

  if (tabBarOrder) {
    NSMutableArray *newViewControllers =
      [NSMutableArray arrayWithCapacity:initialViewControllers.count];

    for (NSNumber *tabBarNumber in tabBarOrder) {
      NSUInteger tabBarIndex = [tabBarNumber unsignedIntegerValue];
      [newViewControllers addObject:[initialViewControllers objectAtIndex:tabBarIndex]];
    }

    self.tabBarController.viewControllers = newViewControllers;
  }


You need to roll your own solution. Use the UITabBarControllerDelegate's

tabBarController:willEndCustomizingViewControllers:changed:

to capture the time after the user finishes editing the icons. Then you can save the user's setting (e.g. assign a number for each tab, and save it into an array etc.) and load it the next time the program launches.

You may use

[NSUserDefaults standardUserDefaults]; 

for a quick way to save such settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜