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.
Asked
Active
Viewed 1,217 times
0

Mobile App Dev
- 1,824
- 3
- 20
- 45
-
Yes, you are right, button should be rearrange according to orientation of iPad – rptwsthi Jun 17 '11 at 06:32
-
@rptwsthi, thanks but how to rearrange that. I had done but what happen it is displaying old button in the middle of cell and new one as the end of the cell. – Mobile App Dev Jun 17 '11 at 06:33
-
Are you creating new button each time you change the orientation – rptwsthi Jun 17 '11 at 06:45
-
@rptwsthi, Yes so, i want to remove the previous one. How can i do that? – Mobile App Dev Jun 17 '11 at 07:11
-
where you are adding the new new button, just use `[previousButton removeFromSuperview];` (show your code where u are adding new button for better understanding) – rptwsthi Jun 17 '11 at 07:40
1 Answers
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