uchicago-mobi / 2015-Winter-Forum

8 stars 1 forks source link

Cells not resizing #155

Closed thomkel closed 9 years ago

thomkel commented 9 years ago

I'm not sure what I'm doing wrong, but I can't get the cells of the Master View to resize.

I added the following to viewDidLoad:

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

And this is the relevant code in cellForRowAtIndexPath

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"newsCell" forIndexPath:indexPath];

UILabel *titleLabel = (UILabel*)[cell viewWithTag:100];
UILabel *dateLabel = (UILabel*)[cell viewWithTag:101];
UILabel *contentLabel = (UILabel*)[cell viewWithTag:102];

// set label text values

[cell setNeedsDisplay];
[cell layoutIfNeeded];

return cell;

I'm sure I'm missing something obvious here.

tabinks commented 9 years ago

Remember to set the constraints on the cell using autolayout. Also, set the UILabel number of lines to be 0 (unlimited lines). The default is 1 line.

emondai commented 9 years ago

I was able to get it working using this guide: http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout