moreNavigationController 保存设置

发布于 2024-10-18 06:21:10 字数 160 浏览 4 评论 0原文

我的应用程序中有一个选项卡栏,并且它有一个“更多”选项卡,因为有超过五个选项卡。

这个“更多”选项卡是自动生成的,因此我认为它可以“开箱即用”,但是当我尝试进入“编辑”菜单时,用“更多”视图中的图标替换栏上的图标,下次我启动该应用程序时它没有保存。

如何让用户保存这个设置?

I have a tab bar in my application and it has a "More" tab because there are more than 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小姐丶请自重 2024-10-25 06:21:10

正如 futureelite7 所说,这就是要走的路。如果您需要帮助,我们就是这样做的:

- (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];
}

在您的应用程序中DidFinishLaunching

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;
  }

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;
  }
与君绝 2024-10-25 06:21:10

您需要推出自己的解决方案。使用 UITabBarControllerDelegate

tabBarController:willEndCustomizingViewControllers:changed:

来捕获用户完成编辑图标后的时间。然后您可以保存用户的设置(例如,为每个选项卡分配一个编号,并将其保存到数组中等)并在下次程序启动时加载它。

您可以使用

[NSUserDefaults standardUserDefaults]; 

一种快速方法来保存此类设置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文