【问题标题】:How can I have a view controller open only on the first launch如何仅在第一次启动时打开视图控制器
【发布时间】:2014-07-13 11:26:31
【问题描述】:

我用 Xcode 5 构建了一个简单的应用程序,使用了非常基本的功能。由于我的应用程序将拥有大量目标受众,因此我希望它支持不同的语言。我已经完成了翻译部分,但我想要的是一个仅在第一次打开应用程序时显示语言选择的视图控制器。我是开发应用程序的新手,所以请详细解释一下。提前致谢。

【问题讨论】:

  • 应用程序将自动使用当前语言环境的字符串文件。您无需手动操作。
  • java 标签是怎么回事?

标签: java ios macos viewcontroller


【解决方案1】:

使用 NSUserDefaults 在应用启动之间存储数据。您将需要以下内容:

static NSString * const kShowIntroductionKey = @"ShowIntroductionKey";

- (void)showOnFirstLaunch
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    BOOL wasIntroductionShowed = [userDefaults boolForKey:kShowIntroductionKey];

    if (!wasIntroductionShowed){

        // Show your screen here!

        [userDefaults setBool:YES forKey:kShowIntroductionKey];
        [userDefaults synchronize];
    }
}

也可能使用原生 iOS 本地化机制会更好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多