I've created my own CustomTableView
and CustomCell
. The cell is in a xib
, and I'm registering it when initializing the tableView, like this:
[self registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil]
forCellReuseIdentifier:kCustomCellIdentifier];
If I don't do this, I won't be able to define what ReuseIdentifier
should "point" to this class. This is my cellForRow
:
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [self dequeueReusableCellWithIdentifier:
kCustomCellIdentifier forIndexPath:indexPath];
if(!cell)
{
cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell"
owner:self options:nil] objectAtIndex:0];
cell.delegate = self;
[cell initialSetup]; //Other stuff
}
else
[cell resetCell];
//And other awesome stuff
return cell;
}
This 'works'. When I lauch my app, my own custom cells are showing.
However, it turns out the cell is NEVER returned as nil
from [self dequeue..
. Thus, the if-statement if(!cell)
is never true. I have additional setup inside this statement that I want to perform, but I don't know where the cell's are being initialized the first time now. If I remove registerNib
, then this statement is true, but then it's true for all cells, and none will ever be dequeued.
I can probably work around this, and put my initialSetup
(and other stuff) inside the -(id)initWithCoder..
-method in the CustomCell-class, but I'd like to know where my cells are being initialized right now. Why do my cells exist before cellForRowAtIndexPath
?