Reputation: 828
I am using customized table view to show my data from Data Core, it's supposed to be looked like this
but what I've actually got is this
and this is my code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[self.fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
Item *item = [self.items objectAtIndex:indexPath.row];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:100];
nameLabel.text = item.name;
UILabel *catLabel = (UILabel *)[cell viewWithTag:101];
catLabel.text = item.category;
UILabel *amountLabel = (UILabel *)[cell viewWithTag:102];
amountLabel.text = item.amount;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"AccountCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
Upvotes: 1
Views: 319
Reputation: 10264
If you right click the labels in the Storyboard, you can see what outlets they're hooked up to. Check they have a white dot to indicate a connection, then as @jhurton suggests, check your data item is not nil
.
Upvotes: 1
Reputation: 119292
Your other datasource methods are working because you can see that there are cells present, but nothing is populated.
This line:
Item *item = [self.items objectAtIndex:indexPath.row];
Is not usual when you are using a fetched results controller. It should be
Item *item = [self.fetchedResultsController objectAtIndexPath:indexPath];
If you check in the debugger you will see that item is probably nil with your current code.
If that isn't the case then your tags don't match up between the prototype cell and your code. Again, this can be checked in the debugger - the labels will be nil.
Upvotes: 1