消息模块-MessageCell的重用方式
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
Reference in New Issue
Block a user