Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

objective c - Connect Two XIBs To One ViewController

I am, in all basics, wanting to have a view for iPhones, and one for iPads. However, I want to use the same view controllers for both of them, since they are the same thing, just optimized for each device.

I know it's possible to do this, because it is a universal app and the default views for a universal project include one main view for iPhones, and one main view for iPads. However, they're implemented automatically and so I don't know how to replicate this.

So, the jist of this question is: How do you have two xibs connected to one viewcontroller?

Thanks,

  • Jake
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

in code.. wherever you lot the new view ..do like this

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
            self.MainView = [[[YOurViewController alloc] initWithNibName:@"YOurViewController_iPad" bundle:nil]autorelease];

}
else
{
    self.MainView = [[[YOurViewController alloc] initWithNibName:@"YOurViewController_iPhone" bundle:nil]autorelease];
}

You will have to replace the nib name and class name with yours..

Above that...one more important step is to go in each xib file..click on File Owner.. and in the i*dentity inspector* (icons on the top right side) .. make sure it is of class YOurViewController


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...