I have one UIViewController which manage a portrait view and some application logic. However, I need to setup a different view for the landscape orientation. The widgets between the 2 views are mainly the same but their layout is very different.
My first try was to use one UIViewController and one associated XIB. In the XIB, I have two UIView, a LandscapeView for landscape, and a PortraitView for portrait.
myController.xib
|myController (File's Owner)
|landscapeView
|-- myWidget
|-- ...
|portraitView
|-- myWidget
|-- ...
Then myController switch between these views depending on the screen orientation by setting its view property.
In my example, the myWidget are essentially the same between the two views, only their positioning change. The controller has an IBOutlet to one of those, and this IBOutlet is changed programmatically when a orientation change occurs, to point to the correct one.
Is there a better solution?
I checked the AlternateViews sample code from Apple but they use 2 UIViewController for 2 different views. I would like to keep all event/delegate handling code in only one controller, not to split it between 2 controllers.