ios - 关闭 UIViewController 时 EXC_BAD_ACCESS 崩溃

标签 ios uiviewcontroller uinavigationcontroller uistoryboardsegue

我有两个按钮触发到两个不同的 UIViewCOntroller,使用以下代码:

- (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;
    }
}

激活任一按钮都会转到适当的 View Controller ,但会导致此警告:

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

每个 View Controller 上都有一个保存和取消导航栏按钮。除了上面提到的之外,一切都按预期工作,除了 newTransSegue 的 View Controller 上的取消按钮,它会关闭 VC,但会导致应用程序崩溃并出现以下错误:

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

这是我用来关闭 VC 的委托(delegate)方法:

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

我已经这样做了几天,并尝试删除转场并在 Storyboard中重新创建它们,并对导航 Controller 执行相同的操作。我在某个地方出轨了,但看不出具体在哪里。

我肯定需要一些指导。 :)

最佳答案

好的,我研究了@Jay 提供的引用资料。原来我以前见过它,但只看过第 1 部分。在第 2 部分中,我发现了对“启用僵尸对象”的引用,我也这么做了。现在,当应用程序崩溃时,我收到了以下消息:[_UILayoutGuide isDescendantOfView:],它指出了 Storyboard 中的问题。

在检查 Storyboard 时,我发现令人惊讶的是,所讨论的 View Controller 的表示形式与周围的 View Controller 不同。我希望我能截取屏幕截图,但在最激烈的搜索过程中,我没有截取。

无论如何,进一步的研究出现了 this question (and its associated comments) 。我的调查显示,虽然我启用了尺寸类,但由于某种我无法解释的原因,模拟指标下相关 View Controller 的尺寸已设置为“自由形式”。我将其重置为“推断”,现在一切似乎都正常运行 - 没有崩溃。希望我能详细解释一下,但我对结果很满意!

关于ios - 关闭 UIViewController 时 EXC_BAD_ACCESS 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29334284/

相关文章:

ios - 为什么人脸检测只能与 CGImagePropertyOrientation.right 一起使用?

iphone - 将工具栏添加到 UITableViewController

ios - 展开 Segue 不起作用 SWIFT

ios - 内存堆积,在ViewController之间切换,什么是ok的?

cocoa-touch - iPad表格 View 上的UISearchBar消失在导航 Controller 栏下方

ios - 使用 iOS 8 管理 UITableviewCell 的动态高度

iphone - 每个对象有多个委托(delegate)?

iphone - 在标签栏上设置背景图像

swift - View Controller 未正确显示

ios - Swift:如何返回到我的 UIViewController 的同一实例