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!