4

I have a Xib for iPhone and I need a similar view for iPad, only iPad size.

What is the best way of doing this? Can you put both views in the same Xib and somehow specify which one is shown?

Or do I need to be make 2 Xib files and 2 classes?

NMunro
  • 1,282
  • 4
  • 18
  • 33
  • http://stackoverflow.com/questions/5347198/xcode-4-xib-create-ipad-version – iArezki Nov 21 '12 at 15:16
  • general speaking you can use the xib for the iPhone in the iPad project. The method initwithNib:@"YOUR XIB" is given the target xib name – Vinh Nov 21 '12 at 15:16
  • If they are the same view, I would recommend making them dynamic of their frame size. – mkral Nov 21 '12 at 15:16

3 Answers3

4

I ended up using 1 class. I set the file owner of both XIB files to this same class.

I just used the name of the XIB file

So I have 2 xibFiles, iPadXib.xib and iPhoneXib.xib

NSString *nibFileName = (iPadVersion) ? @"iPadXib" : @"iPhoneXib";

ViewControllerName *vc = [[ViewControllerName alloc] initWithNibName:nibFileName bundle:nil];
NMunro
  • 1,282
  • 4
  • 18
  • 33
  • 3
    If you name your XIB files MyThing~ipad.xib and MyThing~iphone.xib then you can call [[ViewControllerName alloc] initWithNibName:@"MyThing" and the correct XIB will automatically be loaded. – Paul Jun 20 '14 at 12:07
2

Or do I need to be make 2 Xib files and 2 classes?

Actually, use three classes and 2 xibs. Like this:

  1. MyClass
  2. MyClass_iPhone: MyClass
  3. MyClass_iPad: MyClass

And the two xibs. It gives you much more flexibility. Keep the common logic on the MyClass, and sub-class the other two for the iPhone and iPad Version.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
1

If you want both iPhone and ipad Create Universal App. Create only One XIB and create all controls only once not need to do it separately. Draw the frame in coding. ie, Create frame separate for both iphone and ipad.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130