我正在尝试使用两个UIAlertViews,但是当我触发它时都弹出。
-(IBAction)continueGame_button:(id)sender {
//=====CHECK IF THERE IS AN ON-GOING GAME, IF SO CONTINUE=====//
AccessCurrentGameData *isThereAnOngoingGameFunction = [AccessCurrentGameData new];
BOOL ongoingGame = [isThereAnOngoingGameFunction checkIfGameOngoing];
[isThereAnOngoingGameFunction release];
NSLog(@"+ + +continueGame_button+ + +");
NSLog(@"ongoingGame = %@\n", (ongoingGame ? @"YES" : @"NO"));
if (ongoingGame == YES) {
NSLog(@"+++++++++ ONGOING GAME +++++++++");
myAlert = [[UIAlertView alloc] initWithTitle:@"Fortsätta spel"
message:@"Det finns ett aktivt spel, klicka Spela eller Tillbaka"
delegate:self
cancelButtonTitle:@"Tillbaka"
otherButtonTitles:@"Spela", nil];
myAlert.tag=kTagContinueGame;
[myAlert show];
[myAlert release];
}
}
-(IBAction)newGame_button:(id)sender {
myAlert = [[UIAlertView alloc] initWithTitle:@"Varning"
message:@"Om du går vidare kommer pågående spel stoppas och nollställas!"
delegate:self
cancelButtonTitle:@"Tillbaka"
otherButtonTitles:@"Fortsätt", nil];
myAlert.tag=kTagNewGame;
[myAlert show];
myAlert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
switch(myAlert.tag ) {
case kTagContinueGame:
NSLog(@"kTagContinueGame");
break;
case kTagNewGame:
NSLog(@"kTagNewGame");
AccessCurrentGameData *zeroCurrentGameFileFunction = [AccessCurrentGameData new];
[zeroCurrentGameFileFunction firstCreationOrRestoreOfGameDataFile];
[zeroCurrentGameFileFunction release];
NewGameViewController * temp = [[NewGameViewController alloc] init];
[self setNewGameViewController:temp];
[temp release];
[[self navigationController] pushViewController:newGameViewController animated:YES];
break;
default:
break;
}
}
答案 0 :(得分:2)
检查您的IBOutlet。您可能有1个按钮连接到您的2个IBAction。
如果是UIButton,请检查touchUpInside
。