0

我正在为 iOS 编写游戏,我想知道如何在每次打开应用程序时打开指令视图控制器。我想要一个开关,上面写着“每次都给我看”。如果他们将其切换为 no,则在打开应用程序时将不再显示说明。

4

1 回答 1

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];
   }
}
于 2013-03-20T14:21:21.607 回答