I have been reading this post from Stuart Logde on how to kill the ViewModel when the view disappears.
http://slodge.blogspot.dk/2013/11/n42-is-my-viewmodel-visible-can-i-kill.html
I have a complex ViewPresenter where sometimes I present a ViewController with a UINavigationController modally and then allow navigation within this. Once navigated into another ViewController and pressing Done, I dismiss the entire UINavigationController and all of its ViewControllers. The ViewWillDisappear is not called on other views than the topmost, since they are already disappeared, hence I need another mechanism.
Would it be wrong to follow an approach like the following in MvxViewController on iOS?
private bool viewModelKilled;
protected override void Dispose (bool disposing)
{
if (!viewModelKilled)
{
var killableViewModel = ViewModel as IKillableViewModel;
if (killableViewModel != null)
{
killableViewModel.KillMe();
}
viewModelKilled = true;
}
base.Dispose (disposing);
}
This is more like the normal 'dealloc' approach in iOS where one often unregister from observing other objects.