Some time App take iphone XIB to load controller

160 Views Asked by At

I am creating an application using Apple's new swift language.

Application is universal, so that I created XIB with '~' operator. Like "MyView~iphone.xib" and MyView~ipad.xib" . But sometimes, even when my application is running in iPad it loads iPhone nib.

I have tried lots of option but still facing the same issue.

People may think this never happens but I am facing this issue.

3

There are 3 best solutions below

0
On

I have had an issue like this objective C but that was way back in iOS 6, I don't know whether this could fix your issue but

Try renaming the files as

MyView~iphone.xib for iPhone
MyView.xib for iPad

Instead of

MyView~iphone.xib
MyView~ipad.xib

I would advise you to use Size classes since it is future proof.

0
On

Hey try using size classes in Interface Builder and you won't need different xibs for both iPhone and iPad. You can take advantage of size classes and setting constraints in storyboard for each of the size class. I recommend you watching WWDC 2014: Session 216.

1
On

It would be better to see the code but i guess your solution is like this

BOOL isPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
UIViewController *myViewController = [[UIViewController alloc] initWithNibName:isPad?@"MyView~ipad.xib":@"MyView~iphone.xib" bundle:nil];