Suppose I have a custom controller called MyCustomUIViewController that extends UIViewController:
public class MyCustomUIViewController : UIViewController
{
//- my class implementation
}
Now I want to override a method like this:
public override void ViewDidLoad()
{
base.ViewDidLoad();
//- other stuff here
}
Is it necessary to call base.ViewDidLoad() or not? Where do I have to call base methods? Before or after custom code (i.e. other stuff here)? I’ve seen many samples where base methods are put after doing stuff or even omitted.
Thank you in advance. Regards.
Yes, when you override you need to call base. Calling base ensures your not short-circuiting what apple may have now or in the future. In addition, it’s a good habit because in deeper inheritance, you can also short-circuit some code that needs to get called.
Typically, you call base first.
For example, it’s the equivalent if this typical objective-c code: