Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialThomas Euget
10,615 PointsIs it possible to update this lesson to the latest version of Xcode / iOS, it doesn't work.
I am using latest version of Xcode/ios. Despite following instructions the cell won't adapt its height to the content of the cell. Would it be possible to help me on this one since I have no idea how to solve it. Thanks vm.
6 Answers
eirikvaa
18,015 PointsI haven't read it through, but this link will probably help you understand why it doesn't function and how to solve it.
Robbert Brouwers
10,035 PointsThe answer is indeed in there Eirik, however implementing is unfortunately not a matter of copy paste; don't know where and how to implement it.
According the appcoda tut it comes down to replacing the code from the video with these two lines:
tableView.estimatedRowHeight = 68.0
tableView.rowHeight = UITableViewAutomaticDimension
But how are these correctly implemented?
Ash Furrow
Treehouse Guest TeacherPutting those in viewDidLoad
should be sufficient – let me know if it works.
Robbert Brouwers
10,035 PointsI've tried to add it to the viewDidLoad in THEntryListViewController.m but get an error: "Unknown type name 'tableView': did you mean UITableView'?"
Do I have to declare/import anything in order for the tableView to be used properly?
Ash Furrow
Treehouse Guest TeacherAh, gotcha. The above code is in Swift, not Objective-C. For Objective-C, you'll need the use the following:
self.tableView.estimatedRowHeight = 68.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
Let me know if that works.
Robbert Brouwers
10,035 PointsWell, the code is working, however it doesn't change the format of the table in simulator, which messes things up:
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.tableView.estimatedRowHeight = 68.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
[self.fetchedResultsController performFetch:nil];
}
picture of simulator here: http://nl.tinypic.com/r/2gws75g/8
ps. I appreciate you're taking the time to look into this!
Ash Furrow
Treehouse Guest TeacherHmm, very curious. Could I ask you to upload a zipped copy of the Xcode project somewhere, or email it to me at ash@ashfurrow.com so I can take a look?
Stephen Peltier
9,681 PointsI was having the same issue and think I figured it out. Did you set UI constraints to the items in your cell? The link above says to add the two lines of code, and also to set the auto layout for the cell
After re-enabling auto layout and putting in some constraints the results I get look like they should.
Ash Furrow
Treehouse Guest TeacherOK I've taken a look (apologies for the delay – moving to NYC from Europe has been quite time-consuming). Yes, just setting the rowHeight
won't work unless you use auto layout constraints, which Stephen Peltier correctly points out that we're not using.
However, continuing to use the non-auto layout method should work. You need to create the heightForRowAtIndexPath
method of UITableViewDelegate
's, then call the heightForEntry:
method on the cell class to calculate its height. Is that method not working?
Donny Gumelar France
Courses Plus Student 1,148 Pointscan i get a look , like what is like ? i mean the code for height problem for non-auto layout
Donny Gumelar France
Courses Plus Student 1,148 Pointsmy table look like this https://www.dropbox.com/s/ttula10wn84lwl3/Screen%20Shot%202015-09-20%20at%2012.23.13%20PM.png?dl=0 . need help form master ash Furrow