- 可可
-
我开始做了一个APP,聊天界面,上面是几个固定的,类似于新浪微博的消息界面,上面是固定的,下面是会话列表
1.自己写一个会话列表继承RCConversationListViewController;
2,设置会话类型;(这里我就不详细说了,融云教学视频很详细,下面才是最重要的,自定义会话列表)
3.出入自己的数据源数据,父类里面有个设置数据源的方法;记住一定要设置conversationModelType的类型为:RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION(用户自定义的会话显示),然后我设置置顶显示 model.isTop = YES;
[objc] view plain copy
//插入自定义会话model
- (NSMutableArray *)willReloadTableData:(NSMutableArray *)dataSource{
if ([PersonInfo.type isEqualToString:@"STUDY"]) {
_titleArr = @[@"系统通知",@"评论",@"点赞"];
}else if ([PersonInfo.type isEqualToString:@"TEACHER"]){
_titleArr = @[@"系统通知",@"评论",@"点赞",@"访客"];
}
for (int i = 0; i<_titleArr.count; i++) {
RCConversationModel *model = [[RCConversationModel alloc]init];
model.conversationModelType = RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION;
model.conversationTitle = _titleArr[i];
model.isTop = YES;
[dataSource insertObject:model atIndex:i];
}
return dataSource;
}
4.设置cell的高度
[objc] view plain copy
#pragma mark - 设置cell的高度
- (CGFloat)rcConversationListTableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 70;
}
5.关闭cell的左滑删除事件;因为头部几个点击是跳转新的控制器,是固定的,不能删除;
[objc] view plain copy
#pragma mark - 设置cell的删除事件
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
RCConversationModel *model = [self.conversationListDataSource objectAtIndex:indexPath.row];
if(model.conversationModelType == RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION){
return UITableViewCellEditingStyleNone;
}else{
return UITableViewCellEditingStyleDelete;
}
}
6.修改cell上面字体的字体样式;RCConversationBaseCell里面没有title和content label等控件,所以需要转化一下;转成RCConversationCell;我用的是平方字体;
[objc] view plain copy
#pragma mark - 修改cell样式
- (void)willDisplayConversationTableCell:(RCConversationBaseCell *)cell atIndexPath:(NSIndexPath *)indexPath{
RCConversationModel *model = [self.conversationListDataSource objectAtIndex:indexPath.row];
if(model.conversationModelType != RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION){
RCConversationCell *RCcell = (RCConversationCell *)cell;
RCcell.conversationTitle.font = [UIFont fontWithName:@"PingFangSC-Light" size:18];
RCcell.messageContentLabel.font = [UIFont fontWithName:@"PingFangSC-Light" size:16];
RCcell.messageCreatedTimeLabel.font = [UIFont fontWithName:@"PingFangSC-Light" size:14];
}
}
7.自定义cell,注意自定义的cell一定要继承于RCConversationBaseCell
[objc] view plain copy
#pragma mark - 自定义cell
- (RCConversationBaseCell *)rcConversationListTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
RongYunListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RongYunListCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"RongYunListCell" owner:self options:nil] firstObject];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.ListOneCount.hidden = YES;
}
NSInteger count = 0;
if(indexPath.row < _badgeValueArr.count){
count = [_badgeValueArr[indexPath.row] integerValue];
}
if(count>0){
cell.ListOneCount.hidden = NO;
cell.ListOneCount.text = [NSString stringWithFormat:@"%ld",count];
}else{
cell.ListOneCount.hidden = YES;
}
RCConversationModel *model = self.conversationListDataSource[indexPath.row];
[cell setRongYunListCellOneUIViewWithModel:model iconName:_iconArr[indexPath.row]];
return cell;
}
8.cell的选中事件
[objc] view plain copy
#pragma mark - cell选中事件
- (void)onSelectedTableRow:(RCConversationModelType)conversationModelType conversationModel:(RCConversationModel *)model atIndexPath:(NSIndexPath *)indexPath{
[self.conversationListTableView deselectRowAtIndexPath:indexPath animated:YES];
if(model.conversationModelType == RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION){
NSString *cellTitle = model.conversationTitle;
if([cellTitle isEqualToString:@"系统通知"]){
//系统消息
NewsSystemSecondViewController *svc = [[NewsSystemSecondViewController alloc]init];
svc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:svc animated:YES];
}else if ([cellTitle isEqualToString:@"评论"]){
//评论
SystemCommentViewController *svc = [[SystemCommentViewController alloc]init];
svc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:svc animated:YES];
}else if ([cellTitle isEqualToString:@"点赞"]){
//点赞
ClickLinckedViewController *svc = [[ClickLinckedViewController alloc]init];
svc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:svc animated:YES];
}else if ([cellTitle isEqualToString:@"访客"]){
//访客
MyVistorsViewController *svc = [[MyVistorsViewController alloc]init];
svc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:svc animated:YES];
}
}else{
//会话列表
RCConversationViewController *conversationVC = [[RCConversationViewController alloc]init];
conversationVC.hidesBottomBarWhenPushed = YES;
conversationVC.conversationType = model.conversationType;
conversationVC.targetId = model.targetId;
conversationVC.title = [self getUserNameWithUserID:model.targetId];
[self.navigationController pushViewController:conversationVC animated:YES];
}
}