Using iOS 8.3 simulator and Xcode 6.3.2.
I'm using the self sizing cells technique in iOS 8, and it works terrifically when the cell has no accessory view, but breaks when the cell has an accessory view. I set constraints on the label inside the cell:
Then I use an estimatedRowHeight
and set the rowHeight
to UITableViewAutomaticDimension
(I'm omitting tableView:numberOfRowsInSection:
here, but it just returns 3 for this example):
@implementation MyTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.estimatedRowHeight = 44.0f;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
cell.titleLabel.text = @"Test comment Test comment Test comment Test comment Test comment Test comment Test comment Test comment Test comment Test comment Test comment ";
return cell;
}
@end
And bam, everything looks great:
But when I add an accessory view in the Storyboard, without changing any of the code:
the first cell goes to hell. Xcode's view debugger tells me the label height is 1785 points, and I had to use a gif to show it here:
I do notice that the other two cells are sized fine. I also note that when I rotate the simulator, the first cell gets resized properly, including after it's rotated back to portrait.
Does anyone know why the accessory view messes this up so badly, and what I can do to fix it? A sample project is available at http://github.com/UberJason/SelfSizingNightmare.
This is a bug indeed. I have sent your project to Apple. There is a reply from Apple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With