问题现象
使用TUIKit demo在群组内发一条较长的消息后撤回消息,cell的高度没变
解决方法
代码:
代码语言:objective-c复制
- (void)revokeMsg:(TUIMessageCellData *)msg
{
V2TIMMessage *imMsg = msg.innerMessage;
if(imMsg == nil){
return;
}
NSInteger index = [_uiMsgs indexOfObject:msg];
if (index == NSNotFound)
return;
[_uiMsgs removeObject:msg];
if (index < self.heightCache.count) {
[self.heightCache replaceObjectAtIndex:index withObject:@(0)];
}
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
TUISystemMessageCellData *data = [imMsg revokeCellData];
[_uiMsgs insertObject:data atIndex:index];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
[self scrollToBottom:YES];
}
代码
代码语言:objective-c复制- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat height = 0;
if(_heightCache.count > indexPath.row){
height = [_heightCache[indexPath.row] floatValue];
}
if (height) {
return height;
}
TUIMessageCellData *data = _uiMsgs[indexPath.row];
height = [data heightOfWidth:Screen_Width];
[_heightCache insertObject:[NSNumber numberWithFloat:height] atIndex:indexPath.row];
return height;
}
有没有效果记得给我反馈哦!