更新时间:2023-02-17 13:42:26
大概是该代码在转换为ARC之前可以正常工作.
Presumably, that code worked correctly before it was converted to ARC.
要修复此问题,您需要在-show
方法中创建对self
的强引用,并在-dismissWithClickedButtonIndex:animated:
中释放该引用(在其中您看到[self autorelease]
被注释掉).
To fix it, you'll need to create a strong reference to self
in the -show
method, and release this reference in -dismissWithClickedButtonIndex:animated:
(where you see [self autorelease]
commented out).
您可以使用一个简单的实例变量来做到这一点:
You can do this with a simple instance variable:
id _selfReference;
在-show
中将self
分配给_selfReference
:
- (void)show
{
_selfReference = self;
...
,然后在您看到[self autorelease]
被注释掉的两个地方,在-dismissWithClickedButtonIndex:animated:
中将_selfReference
设置为nil.
and then set _selfReference
to nil in -dismissWithClickedButtonIndex:animated:
in the two places where you see [self autorelease]
commented out.