Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble loading view when using size classes

I'm having this weird problem with size classes.

I noticed that any UIView which isn't installed in Any-Any size class is not part of the subviews when viewDidLoad is called. Meaning I don't have access to it via my outlet nor does it appear in the [self.view subviews] array.

The subviews are placed fine on screen, and the first time I get to access them is in viewDidAppear.

I'm developing my app only for portrait iPhones so I set my Storyboard for compact width and regular height.

Am I doing something wrong? Do I need my storyboard to support Any-Any even though I don't really use this configuration?

like image 751
Rizon Avatar asked Oct 31 '22 07:10

Rizon


2 Answers

AutoLayout hasn't completed until after the final viewDidLayoutSubviews call just before viewDidAppear.

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    //Do your job with views or with its constraints... 
}
like image 198
arturdev Avatar answered Nov 15 '22 06:11

arturdev


You need your storyboard to support Any-Any even though you don't really use this configuration. You have to enable Size Classes in Interface Builder, to do that please refer the following link.

https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/EnablingAdaptiveSizeDesign.html#//apple_ref/doc/uid/TP40014436-CH1-SW1

like image 38
Piyush Avatar answered Nov 15 '22 06:11

Piyush