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 trial
Harry Stromfelt
2,985 PointsAfter creating custom tableView: tableView content is not showing/views are moving around like crazy
I am trying to program a view which has a tableView contained within it.
After creating custom tableView, instead of just customising the delegate in the viewController implementation, I have come across a problem whereby the cells do not populate. This tableView is the beginning of a messages panel, so at the bottom there is a text view. When I click the text view, I had it so that the whole view would resize so that nothing gets lost behind the keyboard. Now this doesn't seem to work either.
This is my cellForRowAtIndexPath code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
messageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSArray *listOfMessages = [self.infoObject objectForKey:@"eventMessages"];
NSDictionary *message = [listOfMessages objectAtIndex:(indexPath.row)];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *dateComponents = [calendar components:NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute fromDate:[message objectForKey: @"sendDate"]];
cell.messageContentLabel.text = [message objectForKey:@"messageContent"];
[cell.messageContentLabel sizeToFit];
cell.dateLabel.text = [NSString stringWithFormat:@"%ld %ld:%ld",(long)[dateComponents day], (long)[dateComponents hour], [dateComponents minute]];
cell.senderLabel.text = [message objectForKey:@"senderName"];
return cell;
}
The 'infoObject' is a property of the custom tableView's class and is assigned in viewDidLoad of the root view... All of the above code is contained in the .m file for the custom view. The view is linked up to a tableView in the storyboard.
If anyone has had this problem, or knows what I am missing, then please advise! I really appreciate any help, been stuck with this all day! Cheers!
Harry Stromfelt
2,985 Pointsokkkkkk so the issue was down to not setting the initialisation methods for the custom tableView!!! Yaaayyyy. Why does that need to be done? there is no explicit indication to do it.. do these methods instantly get run when the compiler finds the class in the storyboard or something?
Harry Stromfelt
2,985 PointsHarry Stromfelt
2,985 PointsCould it be due to the delegate/datasource not properly being set to self? I know that when you want to override in the main viewcontroller you have to set delegate & datasource to self. Do you have to explicitly do that when creating a UTableView subclass?