I have a UITableView with a custom row. On my custom row I have UILAbel with autosizing by width mask, that is why in portrait it has one width and in landscape another.
In my cellForRowAtIndexPath I should get label width:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
UILabel *myLabel =
(UILabel *)[cell viewWithTag:2];
float width = myLabel.frame.size.width;
}
And when i run application, everything is fine and width is good. But when I rotate device to landscape, cellForRowAtIndexPath called before UILAbel changed its frame, and I’v got the same width as in portrait. So how to be ? How to get right width when I rotate device ? The one idea that comes on my mind is to reload tableView in didRotateForInterfaceOrientation…Is there any other solutions ? Thanks…
UPDATE:
One more thing, when I start application in Landscape mode, width is still like in Portrait. Why ? How to fix that ?
Replace this code with yours. May this will help: