I see some example code with [super viewDidLoad] called before your implementation and after your implementation.
I know you don't always have to call super (as seen in many other discussions). When you do call it, is it expected before or after you code?
This could have consequences depending on what super's implementation does. Though you shouldn't have to know super's implementation to write yours.
Of course this goes for all of UIViewControllers delegate methods (willAppear, didAppear, etc...)
Any thoughts?
In '[super viewDidLoad]', 'super' means the same object as 'self', so the class of this 'super' is B. However, by using 'super', you're telling the compiler that you do not want to invoke class B's 'viewDidLoad' method, but its superclass's 'viewDidLoad'.
No, you don't need to call [super viewDidLoad].
Based on iOS documentation and some discussions on the Internet, it would appear that viewDidLoad is called after view is loaded into memory and it's purpose is to allow for some custom setup of views loaded from nib files (basically a quote from docs).
viewDidLoad() is one of the initialization methods that is called on the initial view controller. viewDidLoad() is called before anything is shown to the user - and it is called only once.
My rule of thumb is: if you're doing something related to initialization, always call the super class's method first (if you are going to call it at all). This gives the super class a chance to do any set-up that you may be relying on later in your method. If you're doing something related to destruction, call the super class's method last. This makes sure that you can rely on the state of the object throughout the execution of your method. Finally, take any other case on a case-by-case basis. For instance, if you're handling an event, you probably want to deal with the event first, and only invoke the super class's method if you chose not to handle the event or if you somehow altered it and want to pass it along the event chain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With