每次我的应用程序打开时打开视图,仅在使用时选择

时间:2013-03-20 14:17:32

标签: iphone ios objective-c

我正在为iOS编写游戏,我想知道如何在每次打开应用程序时打开View Controller指令。我希望有一个开关,上面写着“每次都给我看这个。”如果他们将其切换为否,则在打开应用程序时将不再显示说明。

1 个答案:

答案 0 :(得分:6)

您可以使用NSUserDefaults存储切换值,然后每次在您的应用委托,applicationDidBecomeActive方法中启动应用时检查它。

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
   BOOL switchState = [[NSUserDefaults standardUserDefaults] boolForKey:@"switchKey"];
   if(switchState) {
       //If switch is on create the instance of InstructionViewController
       //you can call any of InstructionViewController methods on it.
       InstructionViewController* intructionsViewController = [[InstructionViewController alloc] init];
       //Present the instance of instruction view on top of your current view
       [self.window.rootViewController presentViewController:controller animated:YES completion:nil];
   }
}