removeFromSuperview随机崩溃

时间:2016-08-01 07:52:21

标签: ios objective-c uiview crash automatic-ref-counting

我不知道如何描述正常场景,在调用removeFromSuperview时会造成0.3%的崩溃。

这里有追踪:

Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x43746553
Crashed Thread: 0
0 libobjc.A.dylib 0x000000019340fbd0 objc_msgSend + 16
1 UIKit 0x000000018771f0e8 ___UIViewWillBeRemovedFromSuperview + 404
2 UIKit 0x0000000187452c0c -[UIView(Hierarchy) removeFromSuperview] + 108
...

所有代码均为:

[_control removeFromSuperview];
_control = nil;

我的确是

它在主线程中打电话。

2.I调试我的应用程序,永远不会遇到崩溃。

这堂课是ARC。

希望很快就会有消息传来。

2016年9月2日

我尝试用这些

保护后再次见到它
if(_control && _control.superview) {
   [_control removeFromSuperview];
    _control = nil;
}

任何建议都值得赞赏,因为我完全被难倒了。

1 个答案:

答案 0 :(得分:0)

我认为您的control对象属于UIViewController,因此当您致电self.control_control时,您实际上会致电yourViewController.control。 但是,如果您尝试调用self.control,而您的UIViewController已经解除分配(它不再存在),则会导致崩溃。

您可以尝试使用self.control对您的控制器的引用来致电weak

__weak MyObject *weakSelf = self;
[weakSelf.control removeFromSuperview];
weakSelf.control = nil;

调用weakSelf.control并未在此处提供任何引用,这意味着当您的UIViewController被取消分配时,您的control也将被解除分配,因此不会再导致崩溃。< / p>

这可能不是问题的真正原因,但这是可能的。