I have a subclass of PFQueryTableViewController that I am trying to show in a container view (as a subview). My problem is that I cannot get the custom cells to show in the tableview. I have verified the following via debugging:
I have everything working here correctly except that the cell actually shows up! What am I missing?
This is my cellForRowAtIndexPath code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{
static NSString *CellIdentifier = @"RoundCell";
RoundCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil)
{
cell = [[RoundCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// get string values from Parse
NSString * teeString =[object objectForKey:@"roundTee"];
NSString* courseString = [object objectForKey:@"roundCourse"];
NSString * courseString2 = [[courseString stringByAppendingString:@" - "]stringByAppendingString:teeString];
NSString * dateString = [object objectForKey:@"roundDate"];
NSString * scoreString = [object objectForKey:@"roundScore"];
NSString * differentialString = [object objectForKey:@"roundDifferential"];
cell.courseNameCell.text = courseString2;
cell.dateCell.text = dateString;
cell.scoreCell.text= scoreString;
cell.differentialCell.text=differentialString;
return cell;
}
The correct method is to call the custom cell in cellForRowAtIndexPath.
Check two basic things:
1. on the storyboard and click on the cell in the Attributes inspector checks that the cell has the correct identifier
2. set the cellForRowAtIndexPath in this way:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{
CustomCell *cell = (CustomCell * )[self.tableView dequeueReusableCellWithIdentifier:@"YOUR CELL NAME" forIndexPath:indexPath];
So in your case try:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{
CustomCell *cell = (CustomCell * )[self.tableView dequeueReusableCellWithIdentifier:@"YOUR CELL NAME" forIndexPath:indexPath];
NSString * teeString =[object objectForKey:@"roundTee"];
NSString* courseString = [object objectForKey:@"roundCourse"];
NSString * courseString2 = [[courseString stringByAppendingString:@" - "]stringByAppendingString:teeString];
NSString * dateString = [object objectForKey:@"roundDate"];
NSString * scoreString = [object objectForKey:@"roundScore"];
NSString * differentialString = [object objectForKey:@"roundDifferential"];
cell.courseNameCell.text = courseString2;
cell.dateCell.text = dateString;
cell.scoreCell.text= scoreString;
cell.differentialCell.text=differentialString;
return cell;
}
Do not forget to import the subclass of custom cell in your File.m
#import "YourCustomCell.h"
and set the cell in the identity inspector