if (round == 10){
UIAlertView *endGame = [[UIAlertView alloc]
initWithTitle: @"End of Game"
message: endMessage
delegate:self
cancelButtonTitle:@"New Game"
otherButtonTitles:nil];
[endGame show];
}
else {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle: title
message: message
delegate:self
cancelButtonTitle:@"Next"
otherButtonTitles:nil];
[alertView show];
}
然后是委托方法:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
[self startNewRound];
[self updateLabels];
}
- (void)endGame:(UIAlertView *)endGame didDismissWithButtonIndex:(NSInteger)buttonIndex
{
[self startOver];
}
就是这样。正如我所提到的,endGame AlertView似乎使用了alertView的委托,因此没有激活[self startOver]
方法。所有方法都有效,只是AlertView使用了不正确的委托方法。
问候,
迈克
答案 0 :(得分:2)
像这样更改你的代码,
if (round == 10){
UIAlertView *endGame = [[UIAlertView alloc]
initWithTitle: @"End of Game"
message: endMessage
delegate:self
cancelButtonTitle:@"New Game"
otherButtonTitles:nil];
endGame.tag = 111;
[endGame show];
}
else {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle: title
message: message
delegate:self
cancelButtonTitle:@"Next"
otherButtonTitles:nil];
alertView.tag = 222;
[alertView show];
}
并将方法委托为,
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(alertView.tag == 111)
{
[self startNewRound];
[self updateLabels];
}
else if(alertView.tag == 222)
{
[self startOver];
}
}
答案 1 :(得分:1)
您不能使用dismisswithbuttonindex两种委托方法,您需要使用标记来处理这种情况。
为两个警报视图提供不同的标记,并在委托对象上进行检查。因此,您可以区分两个警报视图。