Can you detect when a UIViewController has been dismissed or popped?

Published

I have some cleanup that needs to be performed in a shared resource any time one of my view controllers is dismissed/popped/unloaded? This could either be when the user hits the back button on that individual screen or if a call to popToRootViewController is made (in which case, I would ideally be able to clear up every controller that was popped.)

The obvious choice would be to do this in viewDidUnload, but of course, that isn’t how unload works. Is there a way to catch all cases to where the ViewController is removed from the stack?

edit:Forgot to mention that I am doing this using Xamarin so that may or may not impact the answers.

Source: Xamarin.ios Questions

Published
Categorised as Uncategorised Tagged , ,

Answers

-dealloc is probably your best bet. The view controller will be deallocated when it is popped from the stack, unless you are retaining it elsewhere.

viewWillDisappear: and viewDidDisappear: aren’t good choices because they are called any time the view controller is no longer shown, including when it pushes something else on the stack (so it becomes second-from-the-top).

viewDidUnload is no longer used. The system frameworks stopped calling this method as of iOS 6.


Pinkie Mayer

Leave a Reply

Your email address will not be published. Required fields are marked *

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq