6

I am trying to make an app where each view controller (.h/.m) has 2 NIB files... one for portrait, one for landscape. Is this the "standard" way of supporting orientation or must I manually set up the orientation view programmatically? The problem I am facing is that when a user flips the orientation, all views are reset (so the user must re-enter text fields/views input).

Here is my orientation method:

- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];

if(portrait) {
    [[NSBundle mainBundle] loadNibNamed:@"myview-portrait" owner:self options:nil];
    [self setupLayout];
} else{
    [[NSBundle mainBundle] loadNibNamed:@"myview-landscape" owner:self options:nil];
    [self setupLayout];
}

[UIView commitAnimations];

}

1
  • Hello E-man is this method valid?Does it cause any problem while app review by apple?I am using the same way as you have done will there be any problem? Oct 28, 2011 at 11:53

1 Answer 1

7

Apple has a number of different suggestions for supporting multiple orientations in their View Controller Programming Guide in the section titled "Managing a View Controller’s Interface Orientation". You might want to read that section to see if any of their suggestions would better suit your needs.

That being said, I have used the strategy you have presented above in an application and it seemed to work pretty well.

To solve your problem of the views being 'reset' I would suggest that you keep a reference to the data being entered by the user as they move from control to control. Then when your orientation changes, you can repopulate the controls so the user's 'progress' isn't lost.

3
  • 1
    I wish there was a cleaner way... :(
    – Exegesis
    Dec 23, 2010 at 21:41
  • Is this method valid?Will this cause any problem while app review by apple?I am using the same way as this, will there be any problem? Oct 28, 2011 at 11:55
  • 1
    Why wouldn't it be valid? The methods used are public API's. Nov 11, 2011 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.