He creado un prototipo de celda con el identificador "mainViewTableCell" en el archivo del guión gráfico y he conectado la vista de tabla principal con una clase de controlador personalizada llamada "NTTableViewController". He implementado la función "tableView cellForRowAtIndexPath" en NTTableViewController.m de la siguiente manera:¿Sigue obteniendo nil de dequeueReusableCellWithIdentifier?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* MAINVIEW_CELLIDENTIFIER = @"mainViewTableCell";
UITableViewCell *newCell = [tableView dequeueReusableCellWithIdentifier: MAINVIEW_CELLIDENTIFIER];
if (newCell == nil) {
newCell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: MAINVIEW_CELLIDENTIFIER];
[newCell autorelease];
newCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NTContactItem* currentItem = [self.contactItemContainer objectInContainerAtIndex: indexPath.row];
NSString* firstName = currentItem.firstName;
NSString* lastName = currentItem.lastName;
NSString* fullName = [firstName stringByAppendingFormat: lastName];
[newCell.textLabel setText: fullName];
[newCell.detailTextLabel setText: currentItem.mobilePhone];
return newCell;
}
Pero i manteniendo conseguir nula de dequeueReusableCellWithIdentifier y tienen que crear una nueva instancia de la célula cada vez.
Entonces, ¿qué pasa?
El código: project
Gracias a todos de antemano.
¿Seguro que establece el identificador para esta célula prototipo precisamente a esa misma cadena en el guión gráfico? –
@FirozeLafeer Estoy seguro. De hecho, lo revisé primero cuando encontré el problema. –