0

アプリにアラートがあり、ユーザーがOKボタンをクリックすると、新しいいくつかが開きます:しかし、このいくつかは空のままです...ボタンなどは表示されません(どういうわけか、背景が正しく表示されます)。

このアラートは、AppDelegate.m ファイルでアプリを初めて起動したときに開きます。

-(void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        FirstVC *launchViewController = [[FirstVC alloc] init];
        self.window.rootViewController = launchViewController;
        [self.window makeKeyAndVisible];

    }
}

UIWindow の使い方が間違っているのかもしれません。すべての回答に感謝します。(FirstVC は、アラート ボタンがクリックされた後に表示される viewController です)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
    if (! [defaults boolForKey:@"notFL"]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Welcome"
                                                       message: @"..."
                                                      delegate: self
                                             cancelButtonTitle:nil
                                             otherButtonTitles:@"OK",nil];


        [alert show];


        [defaults setBool:YES forKey:@"notFL"];


    }
}
4

1 に答える 1

0

ストーリーボードにあるコントローラーを説明する必要があります。アプリを最初に開いたときにアラートが表示されるのはどのコントローラーですか? あなたの問題は、ストーリーボードで設定したものを取得せずに、FirstVC を初期化するだけであることです。そのインスタンスを取得するには、次のようにする必要があります。

FirstVC *launchViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FirstVC"];

これは、アラートが表示される最初のView Controllerから呼び出すと機能します。あなたが投稿したcoedは、その最初のコントローラーのviewDidAppearメソッドに入れる方が良いと思います。

アプリ デリゲートでこれを行う場合は、別の方法でストーリーボードへの参照を取得する必要があります。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
FirstVC *launchViewController = [storyboard instantiateViewControllerWithIdentifier:@"FirstVC"];
于 2013-05-23T17:35:29.273 に答える