2011-06-20 32 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]; 
} 
相关问题