【问题标题】:Saving tab bar items order and coming back to them when re-launching app [duplicate]保存标签栏项目订单并在重新启动应用程序时返回它们[重复]
【发布时间】:2013-06-29 11:47:31
【问题描述】:

我是编码初学者,正在编写一个在 Xcode 4 中使用 UITabBarController 的应用程序,当然我使用了默认模板。查看this code 在用户重新排列标签栏项目并在用户启动应用程序时将它们加载回来后,我将如何保存它们的顺序?以及我将如何做到这一点,以便在应用程序启动时用户被带到他之前关闭应用程序之前看到的最后一个视图?非常感谢!

【问题讨论】:

  • 链接中提供的GitHub项目中有很多文件。您能否指出与您的问题相关的特定类或代码块?
  • 链接项目中的AppDelegate 似乎已经有一些代码试图修改标签栏项目的顺序并基于NSUserDefaults 设置初始视图控制器。你能提供更多关于什么有效或无效的细节吗?
  • 嗯,没有特定的类或代码块......我没有以任何方式尝试过,我之前做过,但删除了代码并来到这里。

标签: ios objective-c uitabbarcontroller


【解决方案1】:

您可以使用 nsuserdefaults 来保存或任何其他您想要的来源,但这里是来自 UITabBarController: switch to a different view controller programmatically 的代码

if ([[WSFUserDefaults sharedInstance] savedTabBarLocation] > 0) {

        if ([[WSFUserDefaults sharedInstance] savedTabBarLocation] > 3) {
            UIViewController *selectViewController = [tabBarController.viewControllers objectAtIndex:[[WSFUserDefaults sharedInstance] savedTabBarLocation]];
            [tabBarController setSelectedViewController:tabBarController.moreNavigationController];
            [tabBarController.moreNavigationController popToRootViewControllerAnimated:NO];//make sure we're at the top level More
            [tabBarController.moreNavigationController pushViewController:selectViewController animated:NO];
        }
        else {
            [tabBarController setSelectedIndex:[[WSFUserDefaults sharedInstance] savedTabBarLocation]];
        }
    }

【讨论】:

  • 如何在 NSUserDefaults 中保存订单?
  • 所以这段代码是用于以编程方式切换视图?
  • google buddy...我输入 save nsmutablearray in 并把我带到了这个...stackoverflow.com/questions/13143039/… 在代码之间稍作调整,你应该在 10 分钟内得到你需要的东西
猜你喜欢
  • 2010-10-16
  • 1970-01-01
  • 1970-01-01
  • 2020-12-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-01
  • 2013-11-19
  • 1970-01-01
相关资源
最近更新 更多