2016-12-18 4 views
1

私は現在、私が却下不可能にする必要があるUIAlertControllerを持っています。アクションボタンを押してもアラートが消えるべきではありません。UIAlertControllerを却下しないでください

どうすればいいですか?

UIAlertController *alert; 

    int bestScore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"bestScore"] intValue]; 
    if (!bestScore || bestScore < _score){ 
     [[NSUserDefaults standardUserDefaults] setObject:@(_score) forKey:@"bestScore"]; 
     alert = [UIAlertController alertControllerWithTitle:@"GAME OVER " 
                message:[NSString stringWithFormat:@"NEW RECORD! \n SCORE : %d \n\n\n\n\n\n", _score] preferredStyle:UIAlertControllerStyleActionSheet]; 
    } 
    else alert = [UIAlertController alertControllerWithTitle:@"GAME OVER" 
                 message:[NSString stringWithFormat:@"SCORE : %d \n Best score : %d \n\n\n\n\n\n ", _score, bestScore] preferredStyle:UIAlertControllerStyleAlert]; 

    [alert addAction:[UIAlertAction actionWithTitle:@"Try again" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
     [self newGame]; 
     [self addNewView]; 

    }]]; 


     [alert addAction:[UIAlertAction actionWithTitle:@"Answer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
       [alert viewWillDisappear:NO]; 

      }]]; 
[self presentViewController:alert animated:YES completion:nil]; 

お願いします。

+3

情報を表示するには、他の方法を使用/作成する必要があります。警告コントローラは、そのボタンの1つがタップされるとすぐに解除されます。 – Paulw11

+0

'UIAlertController'はシステム' alert'です。あなたは変更できません。カスタム警告を書くことをお勧めします。 – aircraft

答えて

1

UIViewを含むUIViewControllerを作成することをお勧めします。このUIView内では、必要な情報を表示し、必要なカスタムボタンアクションを追加することができます。

UIViewをモーダルビューコントローラのように見せるには、UIVisualEffectViewにUIBlurEffectStyleを追加します。

これは、インターフェイスビルダーで必要なUIViewを追加し、関連するView Controllerクラスをリンクする、あなたのstoryboard/xibを使用して従来のView Controllerを作成するのと同じくらい簡単です。初期設定とユーザーインターフェイスの完了後、viewDidLoadに次のコードを追加します。さらに、必要なアニメーションなどをviewWillAppearear & viewWillDisappear内で実行することができます。

UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight] 
UIVisualEffectsView *blurView = [[UIVisualEffectView alloc] initWithEffect:effect]; 
[self.view insertSubview:blurView atIndex:0]; 
0

あなたはいけない、あなたが

alert.actions[1].enabled = NO 

のようなそれの無効なボタンのアクションはこれはあなたのalertController非dismissableようになりますことができalertControllerを閉じたい場合は、この

のように行うことができます。

関連する問題