3

I have an iPhone app with FirstViewController and SecondViewController with respective views FirstView.xib and SecondView.xib.

Now I want to make this app work with both iPhone and iPad. For iPad I need to merge Firstview.xib and SecondView.xib into a single ThirdView-iPad.xib.

What would be the best approach? Do I need to write another ViewController class for iPad or can I use existing FirstViewController and SecondViewController with single xib?

My research so far says that there is no way to use multiple ViewControllers with single xib. Please let me know the best way to do this.

Thanks

Moshe
  • 57,511
  • 78
  • 272
  • 425
Atif Azad
  • 1,294
  • 1
  • 16
  • 30

3 Answers3

5

if you are using Xcode4 you can use "transition to universal target" and it will do everything needed

http://xcodebook.com/2011/05/making-an-ios-target-universal/

if you dont have it then I recommend to keep controllers out of your xib. xib files will be only containing views for iphone and ipad but the controllers "can" be same. and you can control your logic from the rootviewcontroller, just an idea..it all depends on your project.

Spring
  • 11,333
  • 29
  • 116
  • 185
  • Thanks... My problem is that I have to merge two iPhone views into one iPad view. In that case will it be possible to use same controllers? If yes, how? – Atif Azad Aug 10 '11 at 13:27
  • @Atif it means there will be totally different views, so you can use another controller for that. I recommend you to first create a universal project and try to deploy your app, you will see your possibilities and what you need to do better. and still you can use first "transition to universal target" – Spring Aug 10 '11 at 13:30
3

You would be best of to just create a new ViewController unless you're into masochism. Reusing in that way would most likely be to much trouble, and I'd go with aggregation or inheritance in the case you need to reuse logic in your ViewControllers.

I typically create a base ViewController, say XYZViewController and then create a XYZViewController_iPhone with all iPhone-specials and a separate XYZViewController_iPad for iPads. But if they're totally different I give them unique names and their own NIBs as well as ViewControllers.

Pål Brattberg
  • 4,568
  • 29
  • 40
1

There Are following Rules To Convert The Iphone App to Univarsal App

1) In Plist File Add NSMainNibFile~ipad .... MainWindow_ipad(ipad window).

2) Implement separate Names Xibs (Iphone & ipad)

3)in Target Targeted Device Family set to (iphone/ipad) and set The Frames According To Ipad &iphone For example

if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {

btnHme.frame=CGRectMake(971,6, 32, 32); //ipad

} else {

btnHme.frame=CGRectMake(438,6, 32, 32); //iphone

}

cheers

Srinivas
  • 983
  • 9
  • 21