Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do you call the super method in viewWillAppear, viewDidDisappear, etc...?

In UIViewController's documentation, Apple suggests calling the super at some point in the implementation of viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear, etc... For example, the discussion on viewDidDisappear is:

You can override this method to perform additional tasks associated with dismissing or hiding the view. If you override this method, you must call super at some point in your implementation.

My question is does it matter when the super method is called and, if so, what is the correct time to call it? Should super be called as the first line of the method, the last line, or somewhere in the middle depending on your particular needs?

like image 955
JoJo Avatar asked Sep 30 '11 18:09

JoJo


1 Answers

In viewDidAppear call super first so that your calls will override.

In viewWillDisappear it seems to be a toss up, I have researched that extensively and could not find a conclusive answer and it seems to be 50/50. I have decided to call super last in my code in the same manner we call super last in dealloc.

like image 67
zaph Avatar answered Sep 17 '22 20:09

zaph