I met this issue after I upgraded xcode to 6.3. The former build compiled using xcode 6.2 doesn't have this issue and works great.
The issue is: After switch to other tab and back, or back from push segue, the width of most cells will shrink a little bit. But some don't. And it looks like following
The label content in 2nd line of cell has the correct width. And all cells display content with the correct width after first launch.
In above image, there are two uitableviewcells.
content view : blue;
background view: light green;
content Label: purple;
The bg view and contentLabel in 1st cell shrinked. That's what I don't want.
I use storyboard to set the constraints.
bg view's constraints.
labelview's constraints
I also tried to cache the cell height as per this question UITableView layout messing up on push segue and return. (iOS 8, Xcode beta 5, Swift), but it doesn't work.
//In viewDidLoad
self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.contentInset = UIEdgeInsetsZero;
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
float height = [[self.estimatedRowHeightCache objectForKey:[NSString stringWithFormat:@"%ld", indexPath.row]] floatValue];
if (height) {
return height;
} else {
return UITableViewAutomaticDimension;
}
}
//cache row height. I observed this doesn't been called in first launching in debugging.
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[self.estimatedRowHeightCache setValue:[NSNumber numberWithFloat:cell.frame.size.height] forKey:[NSString stringWithFormat:@"%ld", indexPath.row]];
}
Thanks for your help!