When should I call super?

前端 未结 3 1041
醉酒成梦
醉酒成梦 2020-11-27 18:39

What is the best using of [super ... any method name]. Recently I have found out that In dealloc the [super dealloc] must stand in the same end. Be

3条回答
  •  Happy的楠姐
    2020-11-27 19:12

    Just check the corresponding documentations. For instance, when to call super in overridden methods of UIViewController:

    didReceiveMemoryWarning : You can override this method (as needed) to release any additional memory used by your view controller. If you do, be sure to call the super implementation at some point to allow the view controller to release its view. [Means the order is of no importance.]

    loadView : Your custom implementation of this method should not call super.

    setEditing:animated : This method should invoke super’s implementation before updating its view. [Means the order is of importance.]

    viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear: If you override this method, you must call super at some point in your implementation. [Means the order is of no importance.]

    dealloc: If you implement this method but are building your application for iOS 2.x, your dealloc method should release each object but should also set the reference to that object to nil before calling super. [Means the order is of importance.]

    Did you realize similar rules for super in viewDidLoad and viewDidUnload methods aren't mentioned? Because you don't need to call super in these.

提交回复
热议问题