I am running into an issue using the new registerClass method for UITableView. I register my cell fine, and then when I want to make a cell I do this:
static NSString *imageIdentifier = @"image";
CustomCell *cell = [self.tableView dequeueReusableCellWithIdentifier:imageIdentifier];
if (!cell) {
cell = [[CustomCell alloc] initWithQuestion:self.question reuseIdentifier:imageIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
This may not be the modern way to do it, but it is how I’ve done it before. The issue is that because the new registerClass method makes a new cell for you if there isn’t one in the queue, the if (!aCell) check fails, and the cell isn’t built correctly.
Am I not using this new approach to dequeueing correctly?
1) Set up the cell (in your case the selectionStyle) in the
prepareForReusemethod of your UITableViewCell subclass.2) Set the content of the cell after the
dequeueReusableCellWithIdentifier:call intableView:cellForRowAtIndexPath:delegate method.dequeueReusableCellWithIdentifier:will always return a cell if you have calledregisterClass:with the corresponding identifier.