消息模块-MessageCell的重用方式

This commit is contained in:
fengshuo
2022-04-20 10:49:51 +08:00
parent 44db730ca2
commit ad769aa28d
3 changed files with 80 additions and 33 deletions

View File

@@ -170,10 +170,16 @@
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
MessageCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MessageCell class])];
if (cell == nil) {
cell = [[MessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([MessageCell class])];
}
NIMMessage * message = [self.messages objectAtIndex:indexPath.row];
NSString * identifier = [MessageCell cellContent:message];
///cell
MessageCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
/// identifier
[tableView registerClass:[MessageCell class] forCellReuseIdentifier:identifier];
/// cell
cell = [tableView dequeueReusableCellWithIdentifier:identifier];
}
cell.delegate = self;
[cell renderWithMessage:[self.messages objectAtIndex:indexPath.row]];
return cell;
@@ -285,7 +291,6 @@
_sessionTableView.backgroundColor = UIColor.clearColor;
_sessionTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_sessionTableView.showsVerticalScrollIndicator = NO;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoard)];
[_sessionTableView addGestureRecognizer:tap];
}