title: How to reliablly detect that a UIViewController has been dismissed
body: <p>I need to do things when a ViewController is dismissed, ie:</p>
  
  <ul>
  <li>When “Back” is pressed</li>
  <li>When popToRootViewController is called by a parent if was in a UINavigationController</li>
  <li>when DismissViewController is called by a parent if it was presented</li>
  </ul>
  
  <p>eg I need to unsubscribe from events, or dimiss a presented alert etc.</p>
  
  <p>ViewWillDisappear is not called when popToRootViewController is called by it’s parent so that doesnt work.</p>
  
  <p>WillMoveToParentViewController is only for View Controller containment</p>
  
  <p>Dealloc is no good as that is only when garbage collected. I’m using c# Xamarin anyway and it doesnt work there.</p>
  
  <p>ViewDidUnload is no longer used and was never for this anyway</p>
  
  <p>A ViewController itself should not care how it was presented so how do we find out when it is dismissed?</p>
  
  <p>This seems like an important, basic requirement. How do we unsubsribe to events from a model without this, for example?</p>
  
  <p>This is a similar question, but no good answer:</p>
  
  <p><a href="https://stackoverflow.com/questions/26594510/can-you-detect-when-a-uiviewcontroller-has-been-dismissed-or-popped">Can you detect when a UIViewController has been dismissed or popped?</a>?</p>