viewDidAppear presence in code messes with layout

ぐ巨炮叔叔 提交于 2019-12-02 17:51:18

问题


I have encountered some seriously odd situation.

I have a code looking like this:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; 
}

with the view controller looking like this:

Strangely enough, when I ONLY ADD

- (void)viewDidAppear:(BOOL)animated {
}

even WITHOUT any action inside, it totally messes up with the layout of the view controller and makes it look like this:

I have not added any other line of code then just empty header for viewDidAppear. When deleted, the layout is OK. What the heck is happening here?


回答1:


Your view will change size after viewDidLoad with regard to the status bar and navigation bar (if you have them). If you don't call [super viewDidAppear:animated];, your subviews may not be repositioned properly.



来源:https://stackoverflow.com/questions/18536858/viewdidappear-presence-in-code-messes-with-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!