Reputation: 5122
I have a table view that seems to be working, but it's not displaying text in the cell as expected. In other words when I load the tableView it shows only blank cells, whereas I would expect one cell to display a the text requested in the code below.
Is there anything wrong with my code below?
NOTE: I'm only implementing cellForRowAtIndexPath as my tableView is a subclass of Stanford's CoreDataTableViewController
.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"a_cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (cell == nil) {
NSLog(@"cell is nil");
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
//Page is a managed object entity with a name attribute.
Page *page = [self.fetchedResultsController objectAtIndexPath:indexPath];
//The log below returns the expected string for the name value.
NSLog(@"page.name %@", page.name);
cell.textLabel.text = @"page.name";
return cell;
}
There is only one object or "Page" as of now, so I would expect only one cell in the tableView (the top) to display text. In fact all ate blank.
When I log the indexPath using:
NSLog(@"cellForRowAtIndexPath indexPath %@", indexPath);
I get the following printed once:
cellForRowAtIndexPath indexPath <NSIndexPath 0x836f1d0> 2 indexes [0, 0]
Is that the first cell?
Curiously when I try to color the cell like below the cell remains white also:
cell.backgroundColor = [UIColor redColor];
Below is the header for the tableViewController (mine, not Stanford's). Note the context property, that is so I could pass the coreData managedObjectContext in to perform the fetch I needed.
#import <UIKit/UIKit.h>
#import "CoreDataTableViewController.h"
@interface CDST02TableViewController : CoreDataTableViewController
@property (strong, nonatomic) NSManagedObjectContext *context;
@end
Upvotes: 1
Views: 125
Reputation: 26742
You need to change:
cell.textLabel.text = @"page.name";
To:
cell.textLabel.text = page.name;
If that doesn't work, check if any interface element is hiding the first row ;)
Upvotes: 2