In my project I am required to implement the orientation feature of iPhone. For this I have created two xib files and one UIViewController controller file, one for landscape and other for portrait. I have taken one UIViewController because the content of the xib files are same.
Now I want to load the respective xib file depending on the rotation and the content should remain populated in the TextField when the specific file loads. How should I implement this?
CODE:
if( orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
{
NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"landscapeView" owner:self options:nil]; UIView *viewItem = (UIView *)[nibArray objectAtIndex:0]; self.view = viewItem;
}
else if(orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown)
{
//same above lines only different nib name
}
You can check in your
initmethod ofUIViewControllerdevice orientation using following codeAnd choose .xib file that correspond to current orientation.
Hope, this will work.