Rizon
Rizon

Reputation: 1546

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?

Upvotes: 5

Views: 132

Answers (2)

Piyush
Piyush

Reputation: 1544

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

Upvotes: 1

arturdev
arturdev

Reputation: 11039

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... 
}

Upvotes: 1

Related Questions