Question

In Xcode 5.1, using StoryBoards, I'm having trouble getting a custom UITableViewCell to show it's contents. The cell appears -- I can tap to select it -- but the label text doesn't appear.

I've given the Cell my custom class GCell and identifier MyCell

I've connected an IBOutlets to a label in the prototype cell.

#import <UIKit/UIKit.h>

@interface GCell : UITableViewCell

@property (strong, nonatomic) IBOutlet UILabel *nameLabel;

@end

In my class that extends UITableViewController, I have

@implementation PayGroupViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    NSLog (@"[PayGroupViewController] initWithStyle");

    self = [super initWithStyle:style];
    if (self) {

    }
    return self;
} 

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView.delegate = self;
    self.tableView.dataSource = self;

  //  [self.tableView registerClass:[GCell class] forCellReuseIdentifier:@"MyCell"];

    _groups = [NSMutableArray arrayWithCapacity:20];

    GroupModel *gm = [[GroupModel alloc] init];
    gm.title = @"DINNER";
    gm.names = [NSMutableArray arrayWithCapacity:10];
    [gm.names addObject:@"Me"];
    [gm.names addObject:@"Albert"];
    [_groups addObject:gm];

    NSLog (@"[PayGroupViewController] viewDidLoad. [self groups].count:%d" ,[self groups].count);

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog (@"[PayGroupViewController] tableView. [self groups].count:%d" ,[self groups].count);
    return [self groups].count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog (@"[PayGroupViewController] tableView cellForRowAtIndexPath");
    GCell *c = (GCell *)[tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
    GroupModel *group = [self.groups objectAtIndex:indexPath.row];

    NSLog (@"[PayGroupViewController] group.title: %@",group.title); // Outputs "DINNER"

    c.nameLabel.text = group.title; // It does not show up
    NSLog (@"[PayGroupViewController] cell: %@",c); // outputs <GCell: 0x9976ed0, etc. so it does exist
    NSLog (@"[PayGroupViewController] cell.nameLabel: %@",c.nameLabel); // outputs (null)

    return c;
}

Also, here is the entire xCode project if anyone cares to take a look.

http://www.brainjelly.com/WhoPaid.zip

Note that the prototype cell has a Disclosure Indicator Accessory, but that doesn't appear either.

Thanks… I've looked extensively over the other posts with this issue but none of those solutions helped me.

Was it helpful?

Solution

There are 2 problems in your xCode project.

  1. You shouldn't register custom cell class in your code for prototype cells. Storyboard does that for you. When you register same class, you are basically overriding the one created by storyboard.
  2. In your prototype cell there is an undefined outlet named "title", which is connected to Content View. Define or delete it.

After these, clear the project and recompile, it should be ok.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top