I'm trying to make my app detect if the user is on a iPhone 5 screen or not.
I'm successfully using the following method in other views.
Via a button I call the Xib / view to be loaded
- (IBAction)DemoTapeTwo:(id)sender { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { DemoTapeTwoViewController *Second = [[DemoTapeTwoViewController alloc] initWithNibName:nil bundle:nil]; [self presentViewController:Second animated:YES completion:NULL]; } else { DemoTapeTwoViewController *Second = [[DemoTapeTwoViewController alloc] initWithNibName:@"DemoTapeTwoViewController_iPad" bundle:nil]; [self presentViewController:Second animated:YES completion:NULL]; } I have two xib's,
iPhone 5 one : XViewController_568.xib
iPhone 4 one : XViewController.xib
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle { if ([[ UIScreen mainScreen ] bounds ].size.height == 568 ) { nibName = [NSString stringWithFormat:@"%@_568", nibName]; } if (self = [super initWithNibName:nibName bundle:nibBundle]) { } return self; } This ^ goes in the .m file
It should detect if the screen is a iPhone 5 or iPhone 4 screen and adjust the Xib to it.
However, Xcode errors out :
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle /Users/SamGuichelaar/Library/Application Support/iPhone Simulator/6.1/Applications/321B4512-7BD3-46D8-A944-F12029448326/Parkway Drive Gestures.app (loaded)' with name '(null)_568'' First throw call stack:
So, something goes wrong making it not find the original name of the iPhone 4 Xib.
Can anyone help me?
nilas the nib name. What happens if you change it to [[DemoTapeTwoViewController alloc] initWithNibName:@"DemoTapeTwoViewController" bundle:nil];