Reputation: 3
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.
Upvotes: 0
Views: 1013
Reputation: 2792
There are 2 problems in your xCode project.
After these, clear the project and recompile, it should be ok.
Upvotes: 2