[英]dismissViewControllerAnimated causes EXC_BAD_ACCESS - swift
[英]dismissViewControllerAnimated causes EXC_BAD_ACCESS in iOS 7.1 only
ViewControllerA
使用模态序列打开ViewControllerB
。
ViewControllerA
:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
// ModalSegue is defined in the storyboard to point to ViewControllerB
[self performSegueWithIdentifier:@"ModalSegue" sender:self];
}
ViewControllerB
:
- (IBAction)cancelButtonTapped:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil]; // Causes crash
}
在iOS 7.1中,这将导致EXC_BAD_ACCESS崩溃。 如果启用了“僵尸对象”,则会引发异常:
*** -[ViewControllerB respondsToSelector:]: message sent to deallocated instance 0x12ed7e170
在iOS 7.0中,这可以按预期工作。
有任何想法吗?
编辑:根据LeoNatan的请求,这是ViewControllerB
中的dealloc
方法的堆栈跟踪:
正如聊天中所讨论的那样,问题在于选择器视图的寿命比其视图控制器的寿命更长,导致它试图向其委托发送消息。
解决方案是在dealloc
方法中将选择器视图的委托和数据源设置为nil
。
在iOS 7及更高版本中,将委托和数据源设置为nil
是一种好习惯,因为视图的寿命比其视图控制器的寿命更长,并在发布这些视图之后尝试访问其委托。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.