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

用 Swift 实现轻量的属性监听系统 #30

Open
wuhongxing opened this issue Apr 20, 2017 · 5 comments
Open

用 Swift 实现轻量的属性监听系统 #30

wuhongxing opened this issue Apr 20, 2017 · 5 comments

Comments

@wuhongxing
Copy link

当我第二次push到ThirdViewController的时候,我再次修改他的名字和颜色第二个页面和第三个页面都没有变化,但是我发现他们的值确实是变化了,而当我pop回第一个页面设置的值才生效!

@nixzhu
Copy link
Owner

nixzhu commented Apr 20, 2017

Demo 太久远了,bindNameListener 的实现有缺陷。
nameListenerSet.insert 不会更新同名的元素,可改为先 remove,再 insert,强制更新。
或者把 nameListenerSet 改为字典实现,应该很容易的。

@wuhongxing
Copy link
Author

我是根据你Yep上面的UserDefault里面的listener写的,按你这样写确实没有问题,但是controller的deinit()不执行!等我第二次进入该控制器deinit()才被执行(一进入就被执行)

@nixzhu
Copy link
Owner

nixzhu commented Apr 20, 2017 via email

@wuhongxing
Copy link
Author

我在闭包里面持有了self.namebutton导致了无法释放,我写了一个demo,地址:https://github.com/wuhongxing/Listener,大神帮我看看还有没有什么问题!

@nixzhu
Copy link
Owner

nixzhu commented Apr 21, 2017

[weak self]就应该没问题了。你再在deinit里加一句打印,确保pop后观察到对应Controller的释放即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants