0
votes

I'm new to iPad development so please bear with me. I have an iPad application that has a single XIB file. Within the XIB I have two views, one in portrait and one in landscape.

I have a simple button and text field on both views.

I created a single method to update the textfield to HelloWorld.

On my portrait view I have wired up the textfield and button in FileOwner.

When I run the application in portrait view I can tap the button and HelloWorld appears in the text box.

If I rotate the device in the simulator, the new landscape view appears but the textbox is empty.

So I have a few questions about this approach:

  1. When developing views for landscape and portrait is the correct way creating just one XIB and having both Views in there and then programatically switching to them?
  2. If it is correct to this this, how can I synchronize the data between both views when the device is rotated?
2

2 Answers

0
votes

I've only seen 2 separate xib's used, on called someviewportriat.xib and someviewlandscape.xib, but both initialized with same controller. Not saying this is right approach, but it's what I've seen in few apps.

As for 2 text fields with same data in different views, you'll have to make a data objects/Model that both views can access.

0
votes

After doing more research I have found there are three ways for handling this situation:

  1. Autorotating and Autoresizing
  2. Reframing
  3. Swapping Views

Since I am using the Swapping Views technique, you can define two views in Interface Builder that look exactly the way you want, but it also means that you’ll need to keep track of separate IBOutlets for each view. While it is certainly possible for elements in the views to invoke the same IBActions, they cannot share the same outlets, so you’ll potentially need to keep track of twice as many UI widgets within a single view controller.