lolodiv
lolodiv

Reputation: 106

Size classes with xib files not working

Currently, I'm working on universal app (iPhone / iPad) supported on iOS 7 & iOS 8.

Here is my problem regarding size classes :

  1. My navigation bar is defined into a XiB file (NavBarView.xib)

  2. Inside this file, I have a UIButton that I want to display only on iPhone mode, and a UISearchBar only for iPad mode.

  3. To handle that whitout any line code, I used the new feature "Use size classes" available for views since iOS 8. I defined "size classes" for these two elements inside my XiB file.

    • UISearch for Ipad : Installed for all layouts except Compact Width / Any Height (wC hAny)

    • UIButton fo Iphone : Not installed for all layouts but with Compact Width / Any Height (wC hAny)

This mechanism works pretty fine on iOS 8 for iphone and ipad, but not on iOS 7. However, if I apply these size classes direclty into views contained into the storyboard, it works for iOS 7.

Could anyone explain me why my size classes are not working when they are defined into XiB files on iOS 7 ?

Best Regards and many thanks,

Lorenzo.

Upvotes: 2

Views: 2787

Answers (3)

Vlad Pulichev
Vlad Pulichev

Reputation: 3272

Figured another option. Size classes will not work, if you add xibs view as subview to UIApplication.shared.keyWindow.

View must be in UIViewController view hierarchy to support size classes.

Thanks to @IvanKvyatkovskiy

Upvotes: 0

Fernando Mazzon
Fernando Mazzon

Reputation: 3591

Adding as an answer since saadnib's comment on the original question helped me a lot.

Size classes on XIB files not being backwards compatible is a bug that has been fixed on xCode 6.1.1. Strangely it's not on the patch notes but I can confirm I'm using a single xib to provide 2 different layouts for a cell on iPad and iPhone. This only started working once I updated from 6.0.1 to 6.1.1.

Limitations on backwards compatibility for classes on storyboards still apply, but they can be worked around.

Upvotes: 0

EarlGrey
EarlGrey

Reputation: 2543

Barely anything to do with size classes is supported under iOS 7. Some good answers here: How can Xcode 6 adaptive UIs be backwards-compatible with iOS 7 and iOS 6?

Upvotes: 1

Related Questions