Can I use two xibs with one viewcontroller - re: porting to iPhone 5

后端 未结 3 1093
无人共我
无人共我 2020-12-23 23:03

I just submitted my first app to the app store (yay it was just approved!). I now want to update it to work with (look nicer on) the larger iPhone 5 screen. I don\'t intend

3条回答
  •  隐瞒了意图╮
    2020-12-23 23:39

    Here is a simple, working code sample for your view controller that shows how to load myXib-5.xib on the iPhone 5 and myXib.xib on iPhones/iPods predating the iPhone 5:

    - (void)loadView
    {
        if([[UIScreen mainScreen] bounds].size.height == 568)
        {
            // iPhone 5
            self.view = [[NSBundle mainBundle] loadNibNamed:@"myXib-5" owner:self options:nil][0];
        }
        else
        {
            self.view = [[NSBundle mainBundle] loadNibNamed:@"myXib" owner:self options:nil][0];
        }
    }
    

    It assumes that you are only targeting the iPhone and not the iPad, to keep it simple.

    The XIB's file owner's class property should also be set to the view controller that contains loadView.

提交回复
热议问题