【发布时间】:2015-09-12 19:47:07
【问题描述】:
我正在使用 QuickBlox 框架来构建一个聊天应用程序。下面是 cellForRowAtIndexPath 代码。
有些事情我只想对每个单元格执行一次(例如下载图像),所以据我所知,我应该添加 if (!cell) 块来执行此操作。
但是,即使是第一次加载 tableview,该块也不会真正触发。为什么会这样?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
QBChatMessage *message = [[ChatService shared] messagsForDialogId:self.dialog.ID][indexPath.row];
ChatMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ChatMessageCellIdentifier];
if (!cell) {
// some things I only want to do once here, such as download images. but it never fires
}
[cell configureCellWithMessage:message];
return cell;
}
【问题讨论】:
-
如果您使用了
registerClass:forCellReuseIdentifier:,dequeueReusableCellWithIdentifier不会返回nil。 -
是的。你可以在你知道的文档中找到...
-
@rmaddy 我确实使用了 registerClass...还有其他方法可以让我做我想做的事吗?
-
当然 - 删除
registerClass...的使用。然后你就可以在cellForRow...做你想做的事了。
标签: ios objective-c uitableview tableviewcell