gpt4 book ai didi

ios - [CustomViewController respondsToSelector :]: message sent to deallocated instance

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

这用于我的 ARC 前代码工作正常,但自从重构所有项目以与 ARC 兼容后,我开始遇到此崩溃:

[CustomViewController respondsToSelector:]: message sent to deallocated instance

我的项目是一个带有 Split View的 iPad 应用程序,但与苹果文档相反,之前的开发人员在 Split View之前将另一个 View Controller 放在应用程序启动时可见。所以我知道这不是正确的做法,但正如我所说,它曾经在 ARC 集成之前工作,所以我需要解决这个问题。

包含项目菜单的 Root View Controller ,每个项目显示一个要填写的详细信息表单,然后单击下一步按钮移动到下一个详细信息屏幕等。

当我点击放在 Root View 上的主页按钮返回主视图时,问题就开始了,这里是将用户移动到主屏幕的相关代码:

//this method is in the appdelegate, and it gets called when clikc on home button located on the root view
- (void) showHome
{
homeController.delegate = self;

self.window.rootViewController = homeController;
[self.window makeKeyAndVisible];
}

然后,当我单击按钮返回 Split View( Root View /详细信息 View 在哪里)时,应用程序崩溃并显示上述描述。我使用仪器分析了应用程序,负责的代码行位于 RootViewController 中,在 didSelectRowAtIndexPath 方法中,这里是相关代码:

    if(indexPath.row == MenuCustomViewController){
self.customVC=[[CustomViewController alloc] initWithNibName:@"CustomVC"
bundle:nil];
[viewControllerArray addObject:self.customVC];
self.appDelegate.splitViewController.delegate = self.customVC;
}

customVC 是一个强大的属性,我尝试直接分配并分配给实例变量,但这无助于修复崩溃。有什么想法吗?

编辑:这是仪器给出的堆栈跟踪:

[self.appDelegate.splitViewController setViewControllers:viewControllerArray];//this line caused the crash

[viewControllerArray addObject:self.appDescVC];//this statement is called before the above one

self.custinfoVC=[[CustInfoViewController alloc] initWithNibName:@"CustInfo" bundle:nil];//this statement is called before the above one

self.appDelegate.splitViewController.delegate = self.appDescVC;//this statement is called before the above one

custinfoVCappDescVC 是强大的属性。

最佳答案

我通过在 dealloc 方法中将我的委托(delegate)和数据源设置为 nil 解决了这个问题。不确定它是否对您有帮助,但值得一试。

- (void)dealloc
{
homeController.delegate = nil;

//if you have any table views these would also need to be set to nil
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
}

关于ios - [CustomViewController respondsToSelector :]: message sent to deallocated instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18258013/

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