On my main view controller I have a button which shows another view controller, where some settings can be changed:
PresentViewController (new UINavigationController(anotherViewController), true, null);
For the dismiss of anotherViewController the parent should be responsible. I also have to know if something has changed (saved). Therefore I use events.
I'm attaching the event handlers in viewWillAppear
on my parent view controller
anotherViewController.DismissMe += CancelEventHandler;
anotherViewController.SaveFilter += SaveEventHandler;
and in viewWillDisappear
I'm unsubscribing from it
anotherViewController.DismissMe -= CancelEventHandler;
anotherViewController.SaveFilter -= SaveEventHandler;
Because viewWillDisappear
is triggered when a new view controller is presented, I automatically unsubscribe from the events. When I want to fire the events in anotherViewController I can't, because no one is subscribed to my events.
I have to unsubscribe from the events, because otherwise the view controller is never released.
How can I solve this situation?