Iphone 将iAction添加到UIAlert
我试图让UIAlert在单击按钮时执行两种不同的操作。当用户单击“重新启动”时,游戏将重新启动,当单击主菜单时,游戏将转到主菜单。“重置”按钮工作正常,但IBAction在切换视图时不断给我错误信息Iphone 将iAction添加到UIAlert,iphone,xcode,ios4,xcode4,Iphone,Xcode,Ios4,Xcode4,我试图让UIAlert在单击按钮时执行两种不同的操作。当用户单击“重新启动”时,游戏将重新启动,当单击主菜单时,游戏将转到主菜单。“重置”按钮工作正常,但IBAction在切换视图时不断给我错误信息 // called when the player touches the "Reset Game" button - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// 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];
}
}
}
重置工作正常,但我在iAction上遇到两个错误。”showFlip“未声明(首次在此函数中使用)和预期”;”在“:”标记之前。我不明白为什么会这样说,因为当我在alertview之外发布IBAction时,它工作正常。
任何帮助都将不胜感激,请提前感谢您正在定义一个方法,而不是调用一个!此代码
- (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];
}
你应该试试这个:
// 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];
}
谢谢这就成功了,正如你可能知道的那样,我对这东西还很陌生。