gpt4 book ai didi

ios - UIAlertView 取消按钮使应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 04:28:09 25 4
gpt4 key购买 nike

好吧,我刚刚开始 iOS 开发。我将首先解释我的应用程序的流程:
1.加载名为“appViewController”的 View 。
2. [selfpresentViewController:controlleranimated:YEScompletion:nil];这会加载一个webview
3.完成 webview 后,我将其关闭并以这种方式加载新的 UINavigation:

[self dismissViewControllerAnimated:YES completion:^{
formViewController *fv = [ [formViewController alloc] init ];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:fv] autorelease];
navController.navigationBar.hidden = YES;
[presentingViewController presentModalViewController:navController animated:YES];

}];

5.formViewController 有一个按钮,该按钮附加了事件,以便以这种方式显示警报

UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Oops!"
message:@"test"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[av show];

到目前为止,一切都按预期进行。现在,当我单击“确定”(取消)按钮时,应用程序崩溃并显示 NSZombieEnabled
-[appViewController _deepestDefaultFirstResponder]:消息发送到已释放实例 0x6e6a570 lldb

这里发生了什么?为什么它再次尝试向 appViewController 发送消息? [av show] 之后没有代码

注意:我正在使用 ARC

最佳答案

如果您使用 arc,则代码中的自动释放无效。

这似乎是您的 Root View Controller 在某个时刻被释放,并且当遍历响应者链时,将访问生成的悬空指针。

为了验证这一点,我将在 appViewController 上实现 dealloc 方法并查看它是否被调用。

dealloc {
NSLog(@"Problems ahead.");
}

如果在您期望发生这种情况之前确实被调用(对于 Root View Controller 可能根本不会),您需要找出发生这种情况的原因。您可能在某个地方缺少强有力的引用。检查您的应用程序委托(delegate)并验证您是否对该窗口有强引用,并且您是否将 Controller 设置为 Root View Controller (前提是您不使用 Storyboard)。

Zombies 工具非常适合调试此类问题。它将列出有问题的对象的所有保留和释放。 Here's a short introduction to it .

关于ios - UIAlertView 取消按钮使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12059344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com