I have a table view that loads 3 custom cells. 1 custom cell has an ImageView
in it, and it seems to be the culprit of the table view moving when any cell is tapped.
This is what I've tried, but it hasn't worked.
If I use a static value (i.e. return 180
) it works just fine, but anything other than that the table view jumps.
Anyone know why? Thanks!
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
id model = self.Model[indexPath.row];
if ([model isKindOfClass:[FR self]]) {
ListTableViewCell *cellOne = [tableView dequeueReusableCellWithIdentifier:@"1Cell" forIndexPath:indexPath];
if (!cellOne) {
cellOne = [[ListTableViewCell alloc] init];
FR *fD = (FR *)model;
NSString *title = [NSString stringWithFormat:@"%@", fD.title];
NSString *dateString = [self timeSincePublished:fD.pubDate];
NSString *description = [self removeHTMLTags:fD.description];
NSString *link = [NSString stringWithFormat:@"%@", fD.link];
cellOne.labelHeadline.text = title;
cellOne.labelDescription.text = description;
cellOne.labelPublished.text = dateString;
}
// Make sure the cell's frame is updated
[cellOne setNeedsLayout];
[cellOne layoutIfNeeded];
CGFloat heightOne = [cellOne.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return heightOne + 2;
} else if ([model isKindOfClass:[D self]]) {
// more code
}
As far as I know, this is a bug. The workaround to avoid the table jumping right after tapping a cell is to add:
in your table viewWillDisappear
https://devforums.apple.com/message/1050163#1050163
https://devforums.apple.com/message/1042398#1042398