如果操作从UIAlertView委托开始,则从导航控制器弹出后,UIViewController不会被释放

时间:2011-03-31 23:09:57

标签: iphone objective-c uialertview

请你看看那段代码:

/* This app is a game, the user can click an "abort" button anytime,
 * and he/she is therefore asked for confirmation ("really abort game?")
 */
- (IBAction)btnAbortClicked:(id)sender {
    UIAlertView *alert = [[UIAlertView alloc] init];
    [alert setMessage:@"Really abort game?"];
    [alert setDelegate:self];
    [alert addButtonWithTitle:@"Yes"];
    [alert addButtonWithTitle:@"No"];
    [alert show];
    [alert release];
}

/* Delegate method (I don't like it, I wish I had modal blocking windows) */
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0)
    [self quitGame];
}

/* pop the view controller */
- (void)quitGame {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

问题很简单 - 但显然不足以让我解决。 UIViewController会弹出,但不会被释放。问题与UIAlertView严格相关,因为如果我只是从btnAbortClicked:调用quitGame,则会弹出视图控制器并立即取消分配。

相反,似乎一些神秘的实体保留了它。

你能帮帮我吗?提前谢谢。

1 个答案:

答案 0 :(得分:1)

好吧,我认为在调用clickedButtonAtIndex时你仍然在alertView内。我建议转而使用alertView:disDismissWithButtonIndex,以便在alertview消失后调用。