Ho creato una cella prototipo con identificatore "mainViewTableCell" nel file storyboard e ho collegato la vista tabella principale con una classe di controller personalizzata denominata "NTTableViewController". Ho implementato la funzione "tableView cellForRowAtIndexPath" in NTTableViewController.m come segue:Continua a ricevere nil da 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;
}
Ma io mantenendo sempre nullo da dequeueReusableCellWithIdentifier e devono creare una nuova istanza di cella ogni volta.
Quindi, cosa c'è che non va?
Il codice: project
Grazie a tutti in anticipo.
Sei sicuro di impostare l'identificatore di questo prototipo di cella a esattamente la stessa stringa nello storyboard? –
@FirozeLafeer Sono sicuro. In effetti ho controllato prima quando ho trovato il problema. –