Mal*_*loc 0 memory-management uisplitviewcontroller ios automatic-ref-counting
这用于我的预ARC代码工作正常,但由于重构所有项目是ARC兼容,我开始得到这个崩溃:
[CustomViewController respondsToSelector:]: message sent to deallocated instance
Run Code Online (Sandbox Code Playgroud)
我的项目是一个具有拆分视图的iPad应用程序,但与苹果文档相反,之前的开发人员已经在拆分视图之前在应用程序启动时显示另一个视图控制器.所以我知道这不是正确的方法,但正如我所说它在ARC集成之前曾经工作过,所以我需要解决这个问题.
根视图控制器包含项目菜单,每个项目显示要填充的详细信息表单,然后单击下一个按钮移动到下一个详细信息屏幕,等等.
当我点击根视图上的主页按钮返回主视图时,问题就开始了,这是将用户移动到主屏幕的相关代码:
//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];
}
Run Code Online (Sandbox Code Playgroud)
然后,当我单击按钮返回拆分视图(根/详细信息视图的位置)时,应用程序将崩溃并显示上述说明.我用应用程序分析了应用程序,并且负责的代码行位于RootViewController该didSelectRowAtIndexPath方法中,这里是相关的代码:
if(indexPath.row == MenuCustomViewController){
self.customVC=[[CustomViewController alloc] initWithNibName:@"CustomVC"
bundle:nil];
[viewControllerArray addObject:self.customVC];
self.appDelegate.splitViewController.delegate = self.customVC;
}
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
custinfoVC并且appDescVC是强大的属性.
我通过在dealloc方法中将我的委托和数据源设置为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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5943 次 |
| 最近记录: |