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 trialCristiano Di Marco
5,345 PointsOnly one text line in the UITableCell of the entryListVIewController.
Any suggestion?
2 Answers
Jason Woolard
11,563 PointsCode would help as I don't think I did that tutorial. If you're asking what I think it is you're asking which is make it so more than one text line displays within the UILabel in your UITableCell, then try setting these properties on your UILabel.
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
Hope that helps.
Cristiano Di Marco
5,345 PointsHello Jason, I'm sorry but I was not clear. In the tutorial, you create a ListViewController with the list of posts. These posts are displayed in more lines in the tutorial because it is used to make a UITableViewCell class dynamic cell heights depending on the length of the text. In bodyLabel where text appears, I do not see more than one line, rather than self-adapt based on the length of the post. I checked the storyboard size inspector (autosizing) and also all the code that is identical to that of the tutorial.
EntryCell
-
(CGFloat)heightForEntry:(DiaryEntry *)entry { // defining variables // const CGFloat topMargin = 35.0f; const CGFloat bottomMargin = 80.0f; const CGFloat minHeight = 85.0f;
UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
CGRect boundingBox = [entry.body boundingRectWithSize:CGSizeMake(202, CGFLOAT_MAX) options:(NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName: font}context:nil]; return MAX(minHeight, CGRectGetHeight(boundingBox) + topMargin + bottomMargin);
}
-
(void)configureCellForEntry:(DiaryEntry *)entry { self.bodyLabel.text = entry.body; self.locationLabel.text = entry.location;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"EEEE, MMMM d yyyy"]; NSDate *date =[NSDate dateWithTimeIntervalSince1970:entry.date];
self.dateLabel.text = [dateFormatter stringFromDate:date];
if (entry.image) { self.mainImageView.image = [UIImage imageWithData:entry.image];
} else { self.mainImageView.image = [UIImage imageNamed:@"icn_noImage"]; }
if (entry.mood == DiaryEntryMoodGood) { self.moodImage.image = [UIImage imageNamed:@"icn_happy"];
} else if (entry.mood == DiaryEntryMoodAverage) { self.moodImage.image = [UIImage imageNamed:@"icn_average"]; } else if (entry.mood == DiaryEntryMoodBad) { self.moodImage.image = [UIImage imageNamed:@"icn_bad"]; }
entryListViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; cdmEntryCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; DiaryEntry *entry = [self.fetchedResultsController objectAtIndexPath:indexPath]; [cell configureCellForEntry:entry]; return cell; }
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { DiaryEntry *entry = [self.fetchedResultsController objectAtIndexPath:indexPath]; return [cdmEntryCell heightForEntry:entry]; }