开发者

Call super before or after setting up view?

开发者 https://www.devze.com 2023-01-12 06:08 出处:网络
- (void)viewDidLoad { [super viewDidLoad]; //..do stuff.. } or - (void)viewDidLoad {开发者_开发问答
- (void)viewDidLoad {
    [super viewDidLoad];
//..do stuff..
}

or

- (void)viewDidLoad {开发者_开发问答
//do stuff
    [super viewDidLoad];


Generally, if you're setting things up (e.g. init), super should go first. If you're taking things down (e.g. dealloc), super should go last.


- (void)viewDidLoad {
    [super viewDidLoad];

    //..do stuff..
}

First of all let the super view controller do its initiation and then make yours.

2 reasons:

  • You might depend on that initialization
  • You might want to override super view controller's initialization

Once I had to deal with a bug of one of the developers in my team and eventually the bug was caused exactly by this - the [super viewDidLoad]; was the last line in the viewDidLoad method...

0

精彩评论

暂无评论...
验证码 换一张
取 消