Initialize them from xib file.
JJDTextInputCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"JJDTextInputCell" owner:self options:nil] objectAtIndex:0];
Question
I have a custom UITableViewCell defined in a xib. It has two views in its Content View, a label and a text view.
In my table view controller, using either
JJDTextInputCell *cell = [[SDLTextInputCell alloc] init];
or
JJDTextInputCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TextInputCell" forIndexPath:indexPath];
the IBOutlet is null, so the table view does not show the default text or any text I try to display using
cell.descriptionLabel.text = @"foo";
What is the proper way to initialize custom UITableView cells created using interface builder?
Solution 3
Initialize them from xib file.
JJDTextInputCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"JJDTextInputCell" owner:self options:nil] objectAtIndex:0];
OTHER TIPS
AFAIK, there are two ways to dequeue table cell, you can find them here in the doc. Find them under Creating Table View Cells
. You are using dequeueReusableCellWithIdentifier:forIndexPath:
which always returns a valid cell BUT you need to use registerNib:forCellReuseIdentifier:
function in pair with this. You have to register the class and then you will get a valid cell. Check out this question for reference.
If you are using XIB for custom cell you should use
[self.tableView registerNib:[UINib nibWithNibName:@"TableViewCell" bundle:nil] forCellReuseIdentifier:"CellIdentifier"];
for registering a cell instead of
[self.tableView registerClass:[TableViewCell class] forCellReuseIdentifier:"CellIdentifier"];