I have a TableViewController
, and clicking on a custom cell takes you to a related WebViewController
.
The problem I'm having is that when I tap "Back" in the WebViewController
the Table View Cells in TableViewController
"jump".
Once the Table View starts scrolling they all jump back into the right heights. So I'm assuming it has something to do with heights on the TableViewController
custom cells, but I'm not totally sure.
TableViewController.m
Tried:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
id model = self.Model[indexPath.row];
if ([model isKindOfClass:[Two self]]) {
return 490; // As of 11/13/14
} else { // 2 other custom cells
return tableView.rowHeight; // return the default height
}
}
Also Tried:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
id model = self.Model[indexPath.row];
if ([model isKindOfClass:[One self]]) {
ListTableViewCell *cellOne = [tableView dequeueReusableCellWithIdentifier:@"1Cell"];
CGFloat heightOne = [cellOne.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return heightOne + 2;
} else if ([model isKindOfClass:[Two self]]) {
ListTableViewCellTwo *cellTwo = [tableView dequeueReusableCellWithIdentifier:@"2Cell"];
CGFloat heightTwo = [cellTwo.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return heightTwo + 400;
} else if ([model isKindOfClass:[Three self]]) {
ListTableViewCellThree *cellThree = [tableView dequeueReusableCellWithIdentifier:@"3Cell"];
CGFloat heightThree = [cellThree.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return heightThree + 2;
} else {
return 300;
}
}
UPDATE:
Also tried [cell setNeedsUpdateConstraints];
and [cell setNeedsLayout];
.
Also have tried setting estimatedHeight
multiple different spots, and also added Automatic Row Dimension
in tandem with that.
Help would be appreciated! Will post any extra info needed. Thanks!
I'm only supporting iOS 8. I'm using Auto Layout and Storyboards.
Additional Storyboard info for Custom Cell 2:
Storyboard Constraints:
Try setting the
estimatedRowHeight
in viewDidLoad for your UITableView to help UIKit guess your tableView's row heightI finally solved this issue, the key is to calculate an estimated height. Seems like the more accurate estimate you return, the less jumpiness/choppiness.
I believe that you didn't set the constraint properly. I had the a problem similar to this before and solved by setting the constraints on Leading, Trailing, Top and Bottom spacing to the UILabel.
Play around with the constraints. behavior will start change. keep going until you get what you want.
It doesn't seem as a decesnt technical answer from a professional. But, that how it getting solved with those dummy constraint which apple doesn't introduced properly.
Also, try
[cell setNeedsUpdateConstraints];
before you return cell in cellForRowAtIndexPath. And:[cell setNeedsLayout];