When should I call super?

前端 未结 3 1030
醉酒成梦
醉酒成梦 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条回答
  •  醉梦人生
    2020-11-27 19:12

    The usual rule of thumb is that when you are overriding a method that does some kind of initialization, you call super first and then do your stuff. And when you override some kind of teardown method, you call super last:

    - (void) setupSomething {
        [super setupSomething];
        …
    }
    
    - (void) tearDownSomething {
        …
        [super tearDownSomething];
    }
    

    The first kind are methods like init…, viewWillAppear, viewDidLoad or setUp. The second are things like dealloc, viewDidUnload, viewWillDisappear or tearDown. This is no hard rule, it just follows from the things the methods do.

提交回复
热议问题