控制器的某个Label属性使用了.action 造成该控制器没有调用deinit
HZRZCW opened this issue · comments
Nanmenhaishao commented
如题!!!!!!
LEE commented
代码截图, 闭包内是否加了[weak self] ?
Nanmenhaishao commented
代码截图, 闭包内是否加了[weak self] ?
闭包内没有任何代码也一样会。
LEE commented
??? 我测试了Demo中的页面 都是可以正常deinit的, 可以提供尽可能全的代码截图吗? 方便分析
Nanmenhaishao commented
??? 我测试了Demo中的页面 都是可以正常deinit的, 可以提供尽可能全的代码截图吗? 方便分析
我再测试一下
LEE commented
注意 action回调闭包即使你传入的是一个function, 只要使用了外部变量就会产生引用
LEE commented
Demo中ActionViewController 里 使用的就是function形式, 如果在方法内要访问self, 如下:
weak var `self` = self
func clicked(_ result: ASAttributedString.Action.Result) {
self?.label.backgroundColor = .brown
}
Nanmenhaishao commented
LEE commented
验证了一下, 确实如此, Swift语法的定义, 可以曲线救国的方法只有在方法内嵌套一个子方法调用外部方法了.
weak var `self` = self
func clicked(_ result: ASAttributedString.Action.Result) {
self?.clicked(result)
}
Nanmenhaishao commented
验证了一下, 确实如此, Swift语法的定义, 可以曲线救国的方法只有在方法内嵌套一个子方法调用外部方法了.
weak var `self` = self func clicked(_ result: ASAttributedString.Action.Result) { self?.clicked(result) }
能用就行,不过可以提醒下其他人
ZClee commented
ETmanwenhan commented
这是来自QQ邮箱的假期自动回复邮件。
您好,谢谢你联系我。我会尽快给您回复。
ZClee commented
作者快点解决一下吧
LEE commented
ZClee commented
LEE commented
ZClee commented