关闭 UIViewController 时 EXC_BAD_ACCESS 崩溃 [英] EXC_BAD_ACCESS crash upon dismissing UIViewController

查看:27
本文介绍了关闭 UIViewController 时 EXC_BAD_ACCESS 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个按钮触发转至两个不同的 UIViewCONtrollers,使用以下代码:

I have two buttons triggering segues to two different UIViewCOntrollers, using this code:

- (IBAction)newTransButton:(UIButton *)sender
{
    [self performSegueWithIdentifier:@"newTransSegue" sender:self];
}

- (IBAction)switchAccountButton:(UIButton *)sender
{
    [self performSegueWithIdentifier:@"selectAccountSegue" sender:self];
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];

    if ([[segue identifier] isEqualToString:@"newTransSegue"])
    {
        UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
        AddTransactionVC *atvc = (AddTransactionVC *)navController.topViewController;
        atvc.delegate = self;

        WMMGTransaction *addedTransaction = (WMMGTransaction *)[WMMGTransaction MR_createInContext:localContext];

        addedTransaction.account = self.currentAccount.name;
        atvc.thisTransaction = addedTransaction;
    }

    else if ([[segue identifier] isEqualToString:@"selectAccountSegue"])
    {
        UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
        AccountSelectVC *acctSelVC = (AccountSelectVC *)navController.topViewController;
        acctSelVC.delegate = self;
    }
}

激活任一按钮都会转到适当的视图控制器,但会导致此警告:

Activation of either button segues to the appropriate view controller, but causes this warning:

Warning: Attempt to present <UINavigationController: 0x7fb99b4dd430> on <FirstViewController: 0x7fb99b565dd0> whose view is not in the window hierarchy!

我在每个视图控制器上都有一个保存和一个取消导航栏按钮.除了上面提到的之外,一切都按预期工作,除了 newTransSegue 处的视图控制器上的取消按钮,它关闭了 VC,但由于此错误而导致应用程序崩溃:

I have a Save and a Cancel Navigation bar button on each View controller. Other than as mentioned above, everything works as expected, except for the Cancel button on the View controller at newTransSegue, which dismisses the VC, but crashes the app with this error:

EXC_BAD_ACCESS(代码 = 1,地址 = 0x7f87394af29)

这是我用来关闭该 VC 的委托方法:

Here is the delegate method I use to dismiss that VC:

-(void)addTransactionViewControllerDidCancel
{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

我已经在这工作了几天,并尝试删除 segues 并在故事板中重新创建它们,以及对导航控制器做同样的事情.我在某处出轨了,但看不到确切位置.

I've been at this for a couple of days, and have tried deleting the segues and recreating them in storyboard, as well as doing the same for the navigation controllers. I've gone off the rails somewhere, but can't see exactly where.

我肯定可以使用一些指导.:)

I could sure use some guidance. :)

推荐答案

好的,我研究了@Jay 提供的参考.原来我以前看过它,但只看过第 1 部分.在第 2 部分中,我发现了对 Enable Zombie Objects 的引用,我做到了.现在,当应用程序崩溃时,我收到了以下消息:[_UILayoutGuide isDescendantOfView:],它指出了故事板中的一个问题.

OK, I studied the reference kindly provided by @Jay. Turns out I had seen it before, but only Part 1. In Part 2, I discovered a reference to Enable Zombie Objects, which I did. Now, when the app crashed, I was provided with this message: [_UILayoutGuide isDescendantOfView:], which pointed to an issue in the Storyboard.

在检查 Storyboard 时,我发现令人惊讶的是,所讨论的视图控制器的表示形式与周围的视图控制器的形状不同.我希望我制作了一个屏幕截图,但在激烈的狩猎中,我没有.

Upon examining the Storyboard, I discovered that, surprisingly, the representation of the view controller in question was shaped differently than the surrounding view controllers. I wish I'd made a screenshot, but in the heat of the hunt, I didn't.

无论如何,进一步的研究发现了这个问题(及其相关评论).我的调查显示,虽然我启用了大小类,但由于某种原因我无法解释,模拟度量下的相关视图控制器的大小已设置为自由格式".我将其重置为推断",现在一切似乎都在正常运行——没有崩溃.希望我能详细解释一下,但我对结果很满意!

In any case, further research turned up this question (and its associated comments). My investigation revealed that, while I had Size Classes enabled, for some reason I can't explain, the size of the relevant View Controller under Simulated Metrics had been set to "Freeform." I reset it to "Inferred" and things appear to be operating normally now--no crashes. Wish I could explain it in detail, but I'm happy with the result!

这篇关于关闭 UIViewController 时 EXC_BAD_ACCESS 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆