Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

控制器的某个Label属性使用了.action 造成该控制器没有调用deinit #44

Closed
HZRZCW opened this issue Apr 7, 2022 · 16 comments
Labels
help wanted Extra attention is needed

Comments

@HZRZCW
Copy link

HZRZCW commented Apr 7, 2022

如题!!!!!!

@lixiang1994
Copy link
Owner

代码截图, 闭包内是否加了[weak self] ?

@HZRZCW
Copy link
Author

HZRZCW commented Apr 7, 2022

代码截图, 闭包内是否加了[weak self] ?

闭包内没有任何代码也一样会。

@lixiang1994
Copy link
Owner

??? 我测试了Demo中的页面 都是可以正常deinit的, 可以提供尽可能全的代码截图吗? 方便分析

@HZRZCW
Copy link
Author

HZRZCW commented Apr 7, 2022

??? 我测试了Demo中的页面 都是可以正常deinit的, 可以提供尽可能全的代码截图吗? 方便分析

我再测试一下

@lixiang1994
Copy link
Owner

注意 action回调闭包即使你传入的是一个function, 只要使用了外部变量就会产生引用

@lixiang1994
Copy link
Owner

Demo中ActionViewController 里 使用的就是function形式, 如果在方法内要访问self, 如下:

        weak var `self` = self
        func clicked(_ result: ASAttributedString.Action.Result) {
            self?.label.backgroundColor = .brown
        }

@HZRZCW
Copy link
Author

HZRZCW commented Apr 7, 2022

Demo中ActionViewController 里 使用的就是function形式, 如果在方法内要访问self, 如下:

        weak var `self` = self
        func clicked(_ result: ASAttributedString.Action.Result) {
            self?.label.backgroundColor = .brown
        }

image

@lixiang1994
Copy link
Owner

验证了一下, 确实如此, Swift语法的定义, 可以曲线救国的方法只有在方法内嵌套一个子方法调用外部方法了.

        weak var `self` = self
        func clicked(_ result: ASAttributedString.Action.Result) {
            self?.clicked(result)
        }

@HZRZCW
Copy link
Author

HZRZCW commented Apr 7, 2022

验证了一下, 确实如此, Swift语法的定义, 可以曲线救国的方法只有在方法内嵌套一个子方法调用外部方法了.

        weak var `self` = self
        func clicked(_ result: ASAttributedString.Action.Result) {
            self?.clicked(result)
        }

能用就行,不过可以提醒下其他人

@HZRZCW HZRZCW closed this as completed Apr 7, 2022
@lixiang1994 lixiang1994 added the help wanted Extra attention is needed label Apr 7, 2022
@lixiang1994 lixiang1994 pinned this issue Apr 7, 2022
@ZClee128
Copy link

重新打开吧,有别的问题
image
zhe zhon这种写法也是会导致不走deinit

@ETmanwenhan
Copy link

ETmanwenhan commented Apr 23, 2024 via email

@ZClee128
Copy link

作者快点解决一下吧

@lixiang1994 lixiang1994 reopened this May 6, 2024
@lixiang1994
Copy link
Owner

重新打开吧,有别的问题 image zhe zhon这种写法也是会导致不走deinit

是的, 上面有人提到了

@ZClee128
Copy link

ZClee128 commented May 6, 2024

重新打开吧,还有其他问题图像zhon这种写法也会导致走不了deinit

是的,上面有人提到过

我看到很长时间没有解决,希望大佬可以抓紧时间修复一下

@lixiang1994
Copy link
Owner

重新打开吧,还有其他问题图像zhon这种写法也会导致走不了deinit

是的,上面有人提到过

我看到很长时间没有解决,希望大佬可以抓紧时间修复一下

这受限于Swift特性, 我无法解决, 只能建议绕开这种用法

@ZClee128
Copy link

ZClee128 commented May 7, 2024

重新打开吧,还有其他问题图像zhon这种写法也会导致走不了deinit

是的,上面有人提到过

我看到很长时间没有解决,希望大佬可以抓紧时间修复一下

这受限于Swift特性, 我无法解决, 只能建议绕开这种用法

好吧😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants