私は iOS 用のゲームを書いていますが、アプリを開くたびに View Controller の指示を開く方法を知りたいと思っていました。「毎回これ見せて」というスイッチが欲しい。no に切り替えると、アプリを開いたときに指示が表示されなくなります。
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 に答える