2011-06-20 3 views
0

ボタンをクリックしたときに2つの異なるアクションを実行するようにUIAlertを取得しようとしていました。ユーザーが再起動をクリックすると、ゲームが再開し、メインメニューがクリックされると、ゲームはメインメニューに移動します。リセットボタンは正常に機能していますが、IBActionはビューの切り替えに関するエラーを表示し続けます。UAlertにIBActionを追加する

// called when the player touches the "Reset Game" button 
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    // the user clicked one of the OK/Cancel buttons 
    if (buttonIndex == 0) 
    { 
     [self resetGame]; 
    } 
    else 
    { 
     - (IBAction)showFlip:(id)sender { 
      Menu *menuView = [[[menu alloc] init] autorelease]; 
      [gameView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
      [self presentModalViewController:menuView animated:YES]; 

     } 

    } 



    } 

リセットは正常に機能しますが、IBActionでは2つのエラーが発生しています。 'showFlip'は宣言されていません(この関数では最初に使用されます)。 before ':'トークン。なぜ私はIBActionをalertviewの外に投稿するとうまく動作するのか理解できません。 ご連絡ありがとうございます。ありがとうございます。

答えて

4

メソッドを定義していますが、呼び出すことはありません。このコード

- (IBAction)showFlip:(id)sender { 
      Menu *menuView = [[[menu alloc] init] autorelease]; 
      [gameView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
      [self presentModalViewController:menuView animated:YES]; 

     } 

はこの機能の中には存在しません。あなたはこれを試してみてください

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    // the user clicked one of the OK/Cancel buttons 
    if (buttonIndex == 0) 
    { 
     [self resetGame]; 
    } 
    else 
    { 
     [self showFlip]; 
    } 
} 

-(void)showFlip{ 
    Menu *menuView = [[[menu alloc] init] autorelease]; 
    [gameView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [self presentModalViewController:menuView animated:YES]; 
} 
+3

感謝を!それは、あなたがおそらく私がこのようなことにかなり新しいと言うことができるので、トリックをしました。 – MacN00b

+1

@ MacN00bお手伝いします。 – PengOne

4

こと、それを引き出し:

// called when the player touches the "Reset Game" button 
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    // the user clicked one of the OK/Cancel buttons 
    if (buttonIndex == 0) 
    { 
     [self resetGame]; 
    } 
    else 
    { 
     [self showFlip:nil]; 
    } 
} 

- (IBAction)showFlip:(id)sender { 
    Menu *menuView = [[[menu alloc] init] autorelease]; 
    [gameView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [self presentModalViewController:menuView animated:YES]; 
} 
関連する問題