In a view controller I create an array of subviews, which can be removed from the parent view at any time, so their lifespan is shorter than that of the view controller.
When creating them I do pretty much this:
- Alloc/init the subview
- add the view controller as an observer of the subview's
frame
property. - add it to a retained array
- add it to the view
- release it
The subview doesn't have a reference to the view controller.
When the user removes the subview, it gets deallocated, and I get a error in the console telling me the observer of the view's frame
key path has not been removed.
How can I remove the observer when the subview being observed does not keep a reference to observer?
Isn't there anyway to do something like removeAllObservers
?
I would prefer not to have to create a reference to the observer in the subview, as it somewhat defeats the point of KVO (I might as well use a delegate set up).