0

In my application, i want to load different .xib for different orientation i.e. one for portrait , one for landscape

I searched it and found solutions too, but it isn't working for me. Anybody please help me out with this.

Here is my code:-

- (void)viewDidLoad {
    [super viewDidLoad];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];
}

- (void) orientationChanged:(NSNotification *)note {
    UIDevice * device = note.object;
    NSArray *array;
    UIView *mainView;
    if (device.orientation == UIDeviceOrientationPortrait || device.orientation == UIDeviceOrientationPortraitUpsideDown) {
        array = [[NSBundle mainBundle] loadNibNamed:@"NewViewController" owner:self options:nil];
        mainView = [array objectAtIndex:0];
        NSLog(@"Portrait");
    } else {
        array = [[NSBundle mainBundle] loadNibNamed:@"Landscape" owner:self options:nil];
        mainView = [array objectAtIndex:0];
        NSLog(@"Landscape");
    }
}

Thanks in advance!

Stefan
  • 5,203
  • 8
  • 27
  • 51
nickAtStack
  • 163
  • 8
  • 2
    Try this https://github.com/michaeltyson/TPMultiLayoutViewController – yen Oct 31 '13 at 08:11
  • thank you for the link, but i needs to change compiler to Default compiler(APPLE LLVM 5.0),(will it create problems in future ?) also ,I don't think it's gonna help me with this as it's managing layouts for different orientations, but i have to change some elements too.. Do i have any option for that ? – nickAtStack Oct 31 '13 at 10:18

0 Answers0