在我的TableView中,我有一个NSMutableArray * currList的数据源 - 它包含对象代理的对象。我创建了自定义TableCell并正确设置了一切。我发现问题,而显示数据:iOS:自定义TableViewCell - 初始化自定义单元格
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"ChatListCell";
// Custom TableViewCell
ChartListCell *cell = (ChartListCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
// I believe here I am going wrong
cell = [[ChartListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
NSLog(@"Cell = %@", cell); // Shows null
}
/*
With UITableViewCell, things are working perfectly fine
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
*/
Agent *agent = (Agent *)[currChatList objectAtIndex:indexPath.row];
NSLog(@"Agent name - %@", agent.name); // Prints proper data
cell.nameLabel.text = agent.name;
cell.thumbImageView.image = [UIImage imageNamed:agent.photo];
cell.timeLabel.text = agent.chatTime;
return cell;
}
正如你可以看到上面的代码中的注释,如果我评论的定制ChartListCell和使用的UITableViewCell,它工作正常。但与ChartListCell,什么都没有出现,在日志中我得到“Cell = null”&代理名称正确显示。 单元格不应该为空。为什么它是空的,任何人都可以请帮我解决这个问题。我在哪里做错了?
任何帮助,高度赞赏。
感谢
你是否在代码中的其他地方注册了你的自定义细胞笔尖或类? – Alex
当您使用ChartListCell时,单元格是否显示代理的名称/照片? – RaffAl
你在哪里创建了这个自定义单元格?故事情节? XIB? – rdelmar