iOS--环信修改会话列表和聊天的头像昵称(无需自己的服务器)

本文介绍了在iOS应用中如何在环信的会话列表和聊天界面中自定义显示头像和昵称,无需依赖服务器提供数据。通过继承环信提供的视图控制器并实现相关协议方法,实现会话列表的显示和聊天界面的定制。
摘要由CSDN通过智能技术生成

之前写这块时,服务器给返回头像和昵称,但是过了几天,后台又出问题,让自己写,欺负老实人啊!不和他们见识,把代码整理一下,能用,有问题可以直接留言。

环信的集成什么的都略过,直接看界面的代码

一.会话列表 如图

1.和之前说的一样,消息列表界面不需要自己写,直接继承环信的 EaseConversationListViewController并且遵守协议<EaseConversationListViewControllerDelegate, EaseConversationListViewControllerDataSource>,可以直接参考官方Demo(ios_IM_sdk_V3.3.2),找到文件Chat/ChatList/下的ConversationListController,可以把ConversationListController.h文件的方法直接Copy到自己的项目中,如图:(如果消息页只显示消息列表,没有自己的界面,则只需要继承即可,无需实现途中方法)

代码

@interface HYNMessageListController : EaseConversationListViewController<EaseConversationListViewControllerDelegate, EaseConversationListViewControllerDataSource,EMChatManagerDelegate,EMGroupManagerDelegate>


@property (weak, nonatomic) id<EaseConversationListViewControllerDelegate>delegate;
@property (weak, nonatomic) id<EaseConversationListViewControllerDataSource>dataSource;

@property (strong, nonatomic) NSMutableArray *conversationsArray;

- (void)refresh;
- (void)refreshDataSource;

- (void)isConnect:(BOOL)isConnect;
- (void)networkChanged:(EMConnectionState)connectionState;

-(void)setupUnreadMessageCount;


@end

2.在viewDidLoad中设置代理 如图

cell行单元中

代码

#pragma mark UITableViewDataSource---不同section的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    if(section == 0){
        
        return 3;
        
    }else{
        
        return [self.dataArray count];
    }
}
#pragma mark UITableViewDataSource---行单元
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0){
        
        NSArray *imgArr = @[@"message_comment",@"message_thumbs",@"message_same_question"];
        NSArray *titleArr= @[@"评论",@"点赞",@"同问"];
        
        MyCell *cell = [MyCell cellWithTableView:tableView];
        
        cell.itemImg.image = [UIImage imageNamed:imgArr[indexPath.row]];
        cell.title.text = titleArr[indexPath.row];
        //cell.pointImg.backgroundColor = UIColorFromRGB(0xF40707);
        
        return cell;
        
    }else{
        
        NSString *CellIdentifier = [EaseConversationCell cellIdentifierWithModel:nil];
        EaseConversationCell *cell = (EaseConversationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        
        // Configure the cell...
        if (cell == nil) {
            cell = [[EaseConversationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        
        if ([self.dataArray count] <= indexPath.row) {
            return cell;
        }
        
        id<IConversationModel> model = [self.dataArray objectAtIndex:indexPath.row];
        cell.model = model;

        
        if (self.dataSource && [self.dataSource respondsToSelector:@selector(conversationListViewController:latestMessageTitleForConversationModel:)]) {
            NSMutableAttributedString *attributedText = [[self.dataSource conversationListViewController:self latestMessageTitleForConversationModel:model] mutableCopy];
            [attributedText addAttributes:@{NSFontAttributeName : cell.detailLabel.font} range:NSMakeRange(0, attributedText.length)];
            cell.detailLabel.attributedText =  attributedText;
        } else {
            cell.detailLabel.attributedText =  [[EaseEmotionEscape sharedInstance] attStringFro
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值