0

I've made a few apps now that work on iPhone 5 and iPhone and it's really becoming a hassle to program and resize everything based on the frame.view.height so this time I made to views in my xib file, one with an iPhone 5 retina UIView and one with the regular UIView... now how do I display one if the user is using an iPhone 4- and the other if they are using an iPhone5+... I'm assuming it will be done somewhere in the app delegate.

I can detect wether or not the user is using an iPhone 5 by checking the superviews frame height in the ViewDidAppear (*It does NOT work in the ViewDidLoad)

But where do I go from there to choose which view I display... I have 1 view controller and both view's content in the xib file are hooked up to that view controlled. The views themselves are not hooked up... only one is with the default "*view" that comes with a blank Xcode project, I don't know how to add a second one.

Thanks!

Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
  • 2
    possible duplicate of [Can I use two xibs with one viewcontroller - re: porting to iPhone 5](http://stackoverflow.com/questions/12678620/can-i-use-two-xibs-with-one-viewcontroller-re-porting-to-iphone-5) – Jesse Rusak Jan 10 '13 at 21:48
  • Not sure if this helps, but [this](http://stackoverflow.com/a/12396752/1354100) is a great answer to how to handle multiple screen sizes. May change your fundamental design decision to use two different views. – Bejmax Jan 10 '13 at 21:58

2 Answers2

2

You can test [UIScreen mainScreen].bounds.size.height instead of your views to accurately find the height of the screen. If it's 480 it's iPhone 4/4s, if it's 568 it's an iPhone 5 4 inch screen

Andrew Tetlaw
  • 2,669
  • 22
  • 27
  • But then what is the best method to choosing which view to use? I can just say `[self.view addSubview:iPhone5View];` But then I am wasting memory displaying both views right? So how do I get rid of the default view and show the iPhone5 view in its place? – Albert Renshaw Jan 11 '13 at 07:26
  • Usually you do it at the view controller level using the `UIViewController` method `- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle`. Actually the link in @JesseRusak's comment above has a good code example using `[[NSBundle mainBundle] loadNibNamed:` in the view controllers `viewDidLoad` method. – Andrew Tetlaw Jan 11 '13 at 07:29
1
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
        // iPhone Classic
    }
    if(result.height == 568)
    {
        // iPhone 5
    }
}
iPhone Developer
  • 459
  • 1
  • 5
  • 14