0
votes

I have a problem with iOS 8 Self Sizing Cells. I am trying to create Self Sizing cells by using this AppCoda Tutorial.

According to this tutorial I have initialised my table view:

[self.tableView registerNib:[UINib nibWithNibName:[Cell1 description] bundle:[NSBundle mainBundle]] forCellReuseIdentifier:Cell1Identifier];
[self.tableView registerNib:[UINib nibWithNibName:[Cell2 description] bundle:[NSBundle mainBundle]] forCellReuseIdentifier:Cell2Identifier];

self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

In each cells implementation file I have initialised a property:

self.label.numberOfLines = 0;

Also, for each cell, I have added Auto Layout constraints:

enter image description here, enter image description here, enter image description here

For the reason I don't know, cells height aren't changing dynamically.

enter image description here

Does anyone know why is that so?

1
I cannot see it clearly in the picture if you already have it, but you need a constraint between the bottom of your UILabel and the bottom of the superview so that the UILabel may "push" the superview. - Markus
There is a constraint "Bottom space to container" with 0 space - Daumantas Versockas
Then that shouldn't be the problem. What is the text in the label? One word only or multiple words? If it's only one word then your issue might be that lineBreakMode is set to NSLineBreakByWordWrapping. Setting it to NSLineBreakByCharWrappingor add another word just for testing might help. It's set to NSLineBreakByTruncatingTail by default (which you actually can see in the picture). - Markus
No, there are numerous words. My UILabel is high enough to display 2 lines of text, so it wraps text and divides it into 2 lines of text, but the height of cell is still static... - Daumantas Versockas
Are you setting this: "self.label.numberOfLines = 0;" inside "awakefromNib" method? - Anand V

1 Answers

0
votes

While setting up self sizing table view cells, one should not use the "heightForRowAtIndexPath" table view delegate method in the view controller.