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