2011-06-20 37 views
0

我試圖讓我的UIAlert在單擊按鈕時執行兩個不同的操作。當用戶點擊重新啓動時,遊戲重新開始,當主菜單被點擊時,遊戲應該進入主菜單。重置按鈕工作正常,但IBAction不斷給我提供有關切換視圖的錯誤。將IBAction添加到UIAlert

// 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兩個錯誤。 'showFlip'未聲明(首次在此函數中使用)和期望';'之前':'令牌。不明白爲什麼會這樣說,因爲當我在alertview之外發布IBAction時,它工作正常。 任何幫助,將不勝感激,在此先感謝

回答

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]; 
} 
相關問題