dismissViewControllerAnimated仅在iOS 7.1中导致EXC_BAD_ACCESS

Dyl*_*and 0 objective-c ios ios7.1

ViewControllerAViewControllerB使用模态segue 打开.

ViewControllerA:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    // ModalSegue is defined in the storyboard to point to ViewControllerB
    [self performSegueWithIdentifier:@"ModalSegue" sender:self];
}
Run Code Online (Sandbox Code Playgroud)

ViewControllerB:

- (IBAction)cancelButtonTapped:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil]; // Causes crash
}
Run Code Online (Sandbox Code Playgroud)

在iOS 7.1中,这会导致EXC_BAD_ACCESS崩溃.如果Zombie Objects已启用,则抛出异常:

*** -[ViewControllerB respondsToSelector:]: message sent to deallocated instance 0x12ed7e170

在iOS 7.0中,这可以按预期工作.

有任何想法吗?

编辑:按照LeoNatan的要求,这里的的堆栈跟踪dealloc的方法ViewControllerB:

堆栈跟踪

Leo*_*ica 6

正如聊天中所讨论的,问题是选择器视图具有比其视图控制器更长的寿命,导致它尝试向其委托发送消息.

该解决方案是选择器视图的委托和数据源设置为nildealloc方法.

对于iOS 7及更高版本,将委托和数据源设置为是一种良好的做法nil,因为视图具有比视图控制器更长的生命周期,并且在释放这些视图后尝试访问它们的委托.