Question

I have a design where UITableViewCells contains an UIImageView. This image should have the same proportion in portrait or landscape, this is why I have a method called when interface orientation changes using UIDeviceOrientationDidChangeNotification notification.

-(void)updateRowHeightForOrientation:(UIInterfaceOrientation)orientation {

    if(!IS_KNOWN_ORIENTATION(orientation))
        return;

    CGFloat rowHeightPortrait = (IPAD ? 320. : 160.);
    CGFloat widthPortrait = (IPAD ? 768. : 320.);
    CGFloat orientationWidth = (IS_PORTRAIT(orientation) ?
                                (IPAD ? 768. : 320.) :
                                (IPAD ? 1024. : 480.));

    CGFloat resultingRowHeight = rowHeightPortrait * orientationWidth / widthPortrait;

    [self.tableView setRowHeight:resultingRowHeight];
//    [self.tableView reloadData]; /* works if uncommented */
}

If the line is not commented the view is redrawn and the row height is set properly. If not, even when using [self.tableView setNeedsDisplay] or [self.tableView setNeedsLayout] the new value of the property is not used.

How can I force reloading the UI so the new value is applied ?

It worked for some time using -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration because the rowHeight property is set before the interface rotates and is redrawn, but for some strange reasons this method is not called anymore...

Thanks for your help !

Was it helpful?

Solution

I think that

[self.tableView beginUpdates];
[self.tableView endUpdates];

causes the table view to re-evaluate all row heights, so you could try this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top