Why/when do we have to call super.ViewDidLoad?

前端 未结 5 1864
你的背包
你的背包 2020-12-13 17:30

Everyone tells me \"Use super.viewDidLoad() because it\'s just like that\" or \"I\'ve been doing it always like that, so keep it\", \"It\'s wrong if you don\'t call super\",

5条回答
  •  攒了一身酷
    2020-12-13 17:57

    When inheriting directly from UIViewController, call super when its documentation tells you to.

    For example, viewWillAppear(Bool) says, "If you override this method, you must call super at some point in your implementation," whereas viewDidLoad() does not.

    If you are not inheriting directly from UIViewController and the class you are inheriting from does not have reliable documentation, or may silently introduce a breaking change requiring that super be called, then always call super.

提交回复
热议问题