【发布时间】:2023-03-19 09:00:01
【问题描述】:
对象在 ARC 模式下被释放并导致崩溃。下面是我的代码;
BlockAlertView* alert = [BlockAlertView alertWithTitle:title message:message];
[alert setCancelButtonWithTitle:NSLocalizedString(@"No", @"No Button") block:nil];
[alert addButtonWithTitle:NSLocalizedString(@"Yes", @"Yes Button") block:^{
//Do Something
}];
[alert show];
它出现了正确的警报视图(这是自定义 UIView),但是当我单击其中一个按钮时它崩溃了。
崩溃日志;
2015-04-07 22:28:17.065 Test[3213:781570] <BlockAlertView: 0x16bb4160>
2015-04-07 22:33:01.746 Test[3213:781570] *** -[BlockAlertView performSelector:withObject:withObject:]: message sent to deallocated instance 0x16bb4160
这里是BlockAlertView的源代码;
目前我无法估计任何线索,这让我老了。 任何意见将不胜感激!
【问题讨论】:
-
什么是
BlockAlertView?显示它的代码。 -
这是我写的,比较长。不知道怎么给你看,即使它在那里,这可能是解除分配的原因吗?
-
当然,创建和调用
show本身并不是保留alert的理由... -
我们肯定需要查看 BlockAlertView。我也特别想看看委托的设置位置,因为如果它没有持续足够长的时间,就会非常可靠地导致这个错误。
-
我将它声明为类属性 strong 并且崩溃已经消失,但我想保留我当前的代码。我在哪里可以发布代码?很长
标签: ios objective-c iphone automatic-ref-counting