Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 Self Sizing Cells With Accessory View

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:

UILabel constraints in a UITableViewCell

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:

UITableView looks fine

But when I add an accessory view in the Storyboard, without changing any of the code:

With accessory view

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:

Huge cell

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.

like image 615
UberJason Avatar asked Jun 25 '15 17:06

UberJason


Video Answer


1 Answers

This is a bug indeed. I have sent your project to Apple. There is a reply from Apple.

enter image description here

like image 171
Bannings Avatar answered Oct 16 '22 20:10

Bannings