How to use auto-detect and self-size cells in iOS8
I have set up autosizing cells with UILabels without issue in iOS8 after this tutorial: http://useyourloaf.com/blog/2014/08/07/self-sizing-table-view-cells.html
But I am having trouble setting up a UIImageView using autosize. I need the images to be different sizes in Landscape versus portrait (so they keep the same aspect ratio). But every time I get the broken layout errors
"<NSLayoutConstraint:0x14554680 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x14564440(200)]>
Since the actual code has quite a few different types of cells (they all work with auto-sizing cells), I installed a simple example of a blue image rendering problem here:
https://github.com/AdrianMW/ios8autosizingCells
I have set limits for the supervisor and adjust the height like so:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kImageCell forIndexPath:indexPath];
cell.heightConstraint.constant = [self heightForOrientation:self.interfaceOrientation];
return cell;
}
Solutions tried
I tried to disable setTranslatesAutosizingMask: on the cell as per some other suggestions, but when I do that I just get blank space instead of the image. I also tried adding the following:
[cell setNeedsDisplay];
[cell layoutIfNeeded];
I saw mention of overriding sizethatfits: to make it work on that cell using the old way, but that doesn't seem to be called on the cell.
Greetings
source to share