1
最初の起動時に表示するウィンドウを取得しようとしていますが、そのウィンドウにテスト用のボタンがあり、firstLaunch = NOに設定されています。なんらかの理由で、ボタンを押した後でも、ビューは閉じられません。NSUserDefaultsは最初の起動時にのみウィンドウを表示する
アプリデリゲート
userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:firstLaunch forKey:@"firstLaunch"];
newViewController = [[NewView alloc]init];
newViewController.appDelegateOutlet = self;
[userDefaults synchronize];
if ([userDefaults boolForKey:@"firstLaunch"]) {
NSLog(@"first launch");
[_window addSubview:newViewController.view];
[userDefaults synchronize];
}
if (![userDefaults boolForKey:@"firstLaunch"]) {
[userDefaults synchronize];
NSLog(@"not first launch");
ボタン固定
-(IBAction)dismissFirstLaunch:(id)sender{
NSLog(@"%@",appDelegateOutlet);
appDelegateOutlet.firstLaunch = NO;
[appDelegateOutlet.userDefaults setBool:appDelegateOutlet.firstLaunch forKey:@"firstLaunch"];
[appDelegateOutlet.userDefaults synchronize];
NSLog(@"%@",[appDelegateOutlet.userDefaults objectForKey:@"firstLaunch"]);
}
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:firstLaunch forKey:@"firstLaunch"];
newViewController = [[NewView alloc]init];
newViewController.appDelegateOutlet = self;
[userDefaults synchronize];
if ([userDefaults boolForKey:@"firstLaunch"]) {
NSLog(@"YE BOY!!");
[_window addSubview:newViewController.view];
[userDefaults synchronize];
}
else
[self continueLaunch];
return YES;
}
を示している賭けます。あなたがそれが動作するかどうかを知らせます。 –
私の問題がうまくいけば、私は削除するビューを得ることができますが、2番目のif文は決して –
と呼ばれません。私はまっすぐ私に言っているのではなく、あなたが私に思いついたのが好きです。私はアプリケーションの残りの部分を、ボタンプレスで呼び出される ' - (void)continueLaunch'という独自のメソッドに起動しました。もう1つのif文はelseに変更され、そこから呼び出されます。 –