• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 关闭 UIViewController 时 EXC_BAD_ACCESS 崩溃

[复制链接]
菜鸟教程小白 发表于 2022-12-12 14:55:17 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

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

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


-(void)prepareForSegueUIStoryboardSegue *)segue senderid)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 上的 Cancel 按钮,它关闭了 VC,但应用程序因以下错误而崩溃:

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

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

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

我已经为此工作了几天,并尝试删除 segues 并在 Storyboard 中重新创建它们,以及对导航 Controller 执行相同的操作。我在某个地方偏离了轨道,但看不到确切的位置。

我当然可以使用一些指导。



Best Answer-推荐答案


好的,我研究了@Jay 提供的引用资料。原来我以前见过它,但只是第 1 部分。在第 2 部分中,我发现了对 Enable Zombie Objects 的引用,我做到了。现在,当应用程序崩溃时,我收到了这条消息:[_UILayoutGuide isDescendantOfView:],它指出了 Storyboard中的一个问题。

在检查 Storyboard 时,我惊讶地发现,所讨论的 View Controller 的表示形式与周围的 View Controller 不同。我希望我做了一个截图,但在狩猎的热潮中,我没有。

无论如何,进一步的研究出现了this question (and its associated comments) .我的调查显示,虽然我启用了 Size Classes,但由于某种我无法解释的原因,Simulated Metrics 下的相关 View Controller 的大小已设置为“Freeform”。我将它重置为“推断”,现在一切似乎运行正常——没有崩溃。希望我能详细解释一下,但我对结果很满意!

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap