5

I have doubt in using 2 XIb's for one class changing on orientations for Ipad. Is it right practice to do? For Ipad in Portrait mode I have one design and for landscape mode I have different design (little similar to portrait, but can't adjust' in portrait). Can I do everything in programming or its fine in using 2 Xib's, what are the complexities or issues I should face in using 2 Xib's?

Cœur
  • 37,241
  • 25
  • 195
  • 267
gopal
  • 212
  • 1
  • 4
  • 12

3 Answers3

8

If you're asking if using two NIBs for your orientations is standard practice then the answer is no.

If your UIs for landscape and portrait are radically different then it would be a more acceptable approach. But you could easily just use a single NIB with two views inside it (one for landscape, one for portrait) instead.

The accepted design pattern that Apple put forward is your view controller manages both landscape and portrait orientations, and either adjusts its view (using autoresizing masks, and also hooking into the various delegate methods triggered upon rotation to add/remove/animate views) or replaces the view with something else.

If your landscape/portrait views are quite different I'd recommend having a single NIB with two views inside it (one for landscape, one for portrait) and adding/removing those two views inside your view controller when you detect rotation.

'Standard practice' is always quite difficult to define, and perhaps some people will disagree with me, but I certainly haven't seen any apps that use two NIBs for their landscape/portrait orientations, and I haven't seen any Apple sample code that does it either. Hope this helps!

lxt
  • 31,146
  • 5
  • 78
  • 83
3

It depends on complexity of programming realization. If you need to replace button, then you should change frame programmatically. If designs are different in portrait and landscape mode, then you should use 2 xib files.

Using 2 xib, it is hard to transport information from one xib to another. E.g. If xib has text field you should copy text in it and put in second xib and etc.

Igor
  • 4,235
  • 3
  • 34
  • 32
  • Thanks everybody for their great suggestions !!Its good using 2 views in one nib,going with this approach – gopal Jan 09 '12 at 06:51
2

You can use the same XIB, but have two different views, one for portrait and one for landscape. In the "didRotateFromInterfaceOrientation:", switch the views depending on the orientation. Check the following link as to how it can be done:

http://www.theappcodeblog.com/2011/03/30/orientation-change-tutorial-change-the-view-when-the-orientation-changes/

Shanti K
  • 2,873
  • 1
  • 16
  • 31
  • Logically It's not possible. If you want to do this then you need to maintain two object for each controller in XIB for protrait and landscape... – Crazy Developer Jan 06 '12 at 11:18
  • ??? why is it not possible? its been done in many applications. Just go through the link provided. We are just gonna have two UIVIEW objects, a single XIB and single Controller. – Shanti K Jan 06 '12 at 11:21
  • I already told that you need two object for each controller in XIB and also in your sample provide in above link is doing the same thing as I say. Now just thought what if controller have many buttons and other controller. That is why I told logicaly it's not good to integrate this way. – Crazy Developer Jan 06 '12 at 11:33
  • It is not necessary to have two different controllers, one for each orientation. In the didRotateFromInterfaceOrientation: of the viewcontroller, we'll just set "view" property of the controller, to either the potraitView or landscapeView. Hope you are not getting confused between view and viewController. – Shanti K Jan 06 '12 at 11:43
  • @CrazyDeveloper.. pls go thro the tutorial once more.. as far as i can see, thr is only ONE viewcontroller. two VIEWs – Shanti K Jan 06 '12 at 11:45
  • just make one example in which you have five textfield and five label on that view and check that how will you manage it in this way. you will get my point what I want to tell you.. – Crazy Developer Jan 06 '12 at 11:57
  • @CrazyDeveloper.. it depends on wht you want to achieve.. If it is just gonna be 5 text fields and 5 buttons, then i wud rather move them around in the same view with each rotation. According to the question, he has mentioned clearly tht the design in portrait and landscape is quite different from each other. The answer was provided to the question asked here. I have coded both the manners and i now the difficulties involved in both. – Shanti K Jan 06 '12 at 12:10
  • @ShantiK K the link is not available :( – SARATH SASI Jul 27 '15 at 06:55
  • @Shanti K : the link is not available :( – SARATH SASI Jul 27 '15 at 06:57