How to tell when a subView is removed a UIView

╄→гoц情女王★ 提交于 2019-12-11 07:39:29

问题


Basically i wanted to implement a popup UIView so i followed what was posted here POP-UP UIView "IMDB App" style

This works very well. However i have one query. My main view is a tableView. so when a view is popped up i disable scrolling in the table. Now when the popup subView is removed, i need to re-enable scrolling. How do i achieve that? i can't use willRemoveFromSuperview because the popup view is loading a different NIB altogether.

Should i use Notifications?

hope i was clear with explaining the scenario.

Thanks in advance!


回答1:


Feloneous Cat has the correct answer. This is the perfect use a @protocol in your popup view along with a registered delegate. Something is triggering that popup view to close. Whatever that trigger is, call the protocol and the delegate can handle the situation as needed.

Furthermore, when protocols are used correctly, your code becomes very reusable within a project as well as in other projects.




回答2:


What you could do is subclass UIView and override removeFromSuperview to send a notification. I don't think there's ever a case where a view gets removed without using the removeFromSuperview method.



来源:https://stackoverflow.com/questions/6442236/how-to-tell-when-a-subview-is-removed-a-uiview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!