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

时间:2022-09-02 20:52:56

would you please look at that piece of code:

请你看看那段代码:

/* 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];
}

The problem is simple - but apparently not enough for me to solve. The UIViewController gets popped, but doesn't get deallocated. And the problem is strictly related to the UIAlertView, because if I just call quitGame from btnAbortClicked:, the view controller is popped and immediately deallocated.

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

Instead, it seems some mysterious entity retains it.

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

Can you help me? Thanks in advance.

你可以帮我吗?提前致谢。

1 个解决方案

#1


1  

Well, I think that you're still inside the alertView when clickedButtonAtIndex is called. I'd suggest moving to alertView:disDismissWithButtonIndex instead, so that you're called after the alertview disappears.

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

#1


1  

Well, I think that you're still inside the alertView when clickedButtonAtIndex is called. I'd suggest moving to alertView:disDismissWithButtonIndex instead, so that you're called after the alertview disappears.

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