2017-02-11 5 views
4

私はいくつかのウェブサイトから入手したが、UIAlertViewをUIAlertControllerに変更しなければならなかったパックマンゲームでこのコードを使用しようとしていますが、次のコードには修正方法がわからないプログラミングに新しい、これは本当に初心者の質問であるように感じる - 申し訳ありません!!)UIAlertControllerの使い方

最初のエラーは、4行目ではありません:セレクタのは知られていないクラスメソッドalertControllerWithTitle

第二にエラーが最終ラインである:目に見えるインターフェースは、セレクタを宣言していません"show"

ありがとうございます!

- (void)collisionWithExit: (UIAlertController *)alert { 

if (CGRectIntersectsRect(self.pacman.frame, self.exit.frame)) { 

    [self.motionManager stopAccelerometerUpdates]; 

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Congratulations" 
                message:@"You've won the game!" 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil 
              preferredStyle:UIAlertControllerStyleAlert]; 
    [alert show]; 

    } 

} 
+0

は 'AlertView'は、より多くのオプションと' UIAlertController'を使用しなければならないので、代わりにあなたのiOSの9で廃止予定され、このコードの下にチェック。 – vaibhav

+0

[役に立つリンク](https://www.google.co.in/?gws_rd=ssl#q=uialertview+deprecated+ios+9+)、少し検索:) – vaibhav

答えて

13

次のコードを確認してください:

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" 
          message:@"This is an alert." 
          preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) {}]; 

[alert addAction:defaultAction]; 
[self presentViewController:alert animated:YES completion:nil]; 
7

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Name" message:@"YOUR ALERT MESSAGE" preferredStyle:UIAlertControllerStyleAlert]; 

    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) 
             { 
              //BUTTON OK CLICK EVENT 
             }]; 
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; 
    [alert addAction:cancel]; 
    [alert addAction:ok]; 
    [self presentViewController:alert animated:YES completion:nil]; 
関連する問題