Can't get my custom UITableViewCell to show

ios, objective-c, uitableview

Solution

You should register the nib like this (probably in viewDidLoad):

[self.tableView registerNib:[UINib nibWithNibName:@"HistoryCell" bundle:nil ] forCellReuseIdentifier:@"historyCellType"];

Then in your cellForRowAtIndexPath method, use this new way where you don't need the if cell == nil clause:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

HistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:@"historyCellType" forIndexPath:indexPath];

cell.nameLabel.text = @"Donald Duck";

return cell;

}

Problem

I am using a TableView xib and all the delegates and datasource seem to be running fine. If I set `self.textLabel.text`, it displays the generic number of tableviews correctly, but I need to have my custom TableViewCell showing. I created a HistoryCell.xib that has just a tableviewcell in it. I created a UITableViewCell class "HistoryCell.h/HistoryCell.m" and it is set as the file owner of HistoryCell.xib. I connected the UILabels to the HistoryCell.h `UILabel statusLabel` `UILabel nameLabel` `UILabel timeLabel` In my main ViewController class int he `cellForRowAtIndexPath` I am putting in ``` - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"historyCellType"; HistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[HistoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.nameLabel.text = @"Donald Duck"; return cell; } ``` What am I doing wrong? Thanks!

Original source