--iOS-OC-Customize the Rongyun IM chat interface, retract the keyboard and go to the input toolbar

I started to make an APP, a chat interface, there are several fixed above, similar to the message interface of Sina Weibo, the above is fixed, and the following is a list of conversations

1. Write a session list to inherit RCConversationListViewController;

2. Set the session type; (I won't go into details here, the Rongyun teaching video is very detailed, the following is the most important, custom session list)

3. To enter and exit your own data source data, there is a method for setting the data source in the parent class; remember to set the type of conversationModelType to: RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION (user-defined session display), and then I set the top display model.isTop = YES ;

//Insert custom session model
- (NSMutableArray *)willReloadTableData:(NSMutableArray *)dataSource{
    if ([PersonInfo.type isEqualToString:@"STUDY"]) {
        _titleArr = @[@"System Notification",@"Comment",@"Like"];
    }else if ([PersonInfo.type isEqualToString:@"TEACHER"]){
        _titleArr = @[@"System Notification",@"Comment",@"Like",@"Visitor"];
    }
    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. Set the height of the cell

#pragma mark - set the height of the cell
- (CGFloat)rcConversationListTableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

5. Turn off the left swipe delete event of the cell; because several clicks on the head jump to the new controller, it is fixed and cannot be deleted;

#pragma mark - set the delete event of the 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. Modify the font style of the font above the cell; there are no controls such as title and content label in RCConversationBaseCell, so it needs to be converted; converted to RCConversationCell; I use a square font;

#pragma mark - Modify cell style
- (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

#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的选中事件

#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];
    }
}

8.效果图


自定义列表DEMO下载地址:http://download.csdn.net/detail/u014220518/9642998


相关文章: 

--iOS-OC-自定义融云IM聊天界面,键盘收回去输入工具栏下去

--iOS-OC-融云会话列表设置群组昵称和头像相关

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325559312&siteId=291194637