When should I call super?

前端 未结 3 1049
醉酒成梦
醉酒成梦 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 18:58

    It mostly depends on whether your subclass needs things to happen before the superclass method, or after. Or both, as the case may be.

    That's why init methods call the super method first thing, and dealloc methods last thing. In your example, when you are being notified that a view will appear, you might want to let the super do its thing, and then, after that, take care of whatever your subclass view needs to do. But it could conceivably be other way around, or you could call the super method in between your code. Different rules will apply according to your application's needs.

提交回复
热议问题