0

I had a table populated with rows and each row contain image, title and a button.
When user change the orientation of the iPad button should be rearrange according to the orientation of iPad. Please advice me how to rearrange the object in uitableview cell.
Thanks in advance.

Mobile App Dev
  • 1,824
  • 3
  • 20
  • 45

1 Answers1

3

This will work :

-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

}

-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}  

Now implement the following method :

-(void)checkOrientation
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight)
    {
        [tblView reloadData];
        // Set x coorinate of views you want to change

    }
    else
    {
        [tblView reloadData];
        // Set x coordinates of views to initial x xoordinates.

    }

}  

Create recievedRotate :

- (void)receivedRotate:(NSNotification *)notification
{    
[self checkOrientation];
}  

In viewDidLoad :

-(void)viewDidLoad
{  
[self checkOrientation];
}
Nitish
  • 13,845
  • 28
  • 135
  • 263