会话页面
会话页面即应用程序中的聊天页面。Global IM UIKit 提供基于 UIKit UIViewController 类实现的会话页面类 RCChatViewController,由导航栏 、消息列表和输入区三部分组成。
会话界面
会话页面以消息对象为元素,展示所有消息对象,也是所有消息的发起入口。Global IM UIKit 中常用的消息类型有:文本、图片、视频、文件、语音、贴纸等,支持回复、转发、复制等常用快捷交互。

导航栏
Global IM UIKit 的 RCChatViewController 使用了系统的导航栏,RCChatHeaderView 继承于 RCBaseHeaderView,用于配置导航条属性。RCChatHeaderView 默认提供以下属性:
backItem对应的左侧按钮会显示会话名称和头像,点击会退出当前页面。支持提示连接状态和输入状态变化提示。moreItem对应的右侧按钮,点击会弹出更多操作菜单。默认支持免打扰、删除消息。
消息列表
Global IM UIKit 的 RCMessageListView 中的消息列表按时间顺序显示所有消息,并根据 RCChatViewConfig 定位到第一条未读消息、最新消息或指定的历史消息。
消息列表的视图基于 UITableView 实现,文本、图片、视频等不同消息类型通过继承 RCMessageCell 实现不同的视图展示。例如,RCTextMessageCell、RCFileMessageCell、RCImageMessageCell 继承自 RCMessageCell,用于展示会话中 RCTextMessage、RCFileMessage、RCImageMessage 等消息。如果自定义消息 Cell,必须根据消息类型注册消息 Cell。
初始化
基于 Global IM UIKit 开发时,推荐继承
RCChatViewController类,创建自定义的会话页面。在排查或复现与会话页面相关的问题时,可以直接使用RCChatViewController类。
RCChatViewController 提供了两个初始化方法:
/// 初始化方法
/// - Parameter chatModel: 会话
- (instancetype)initWithChatModel:(RCChatModel *)chatModel;
/// 初始化方法
/// - Parameter conversationIdentifier: 会话标识
- (instancetype)initWithConversationIdentifier:(RCConversationIdentifier *)conversationIdentifier;
默认从会话列表跳转进会话页面时,调用 initWithChatModel: 方法构建会话页面;如果是从通讯录等其他页面跳转进会话页面,可以调用 initWithConversationIdentifier: 方法构建会话页面。
创建一个继承会话页面的类 TestChatViewController : RCChatViewController
if (self.navigationController) {
TestChatViewController *controller = [[TestChatViewController alloc] initWithChatModel:chatModel];
[self.navigationController pushViewController:controller animated:YES];
} else {
// 如果外部没有用 UINavigationController,需要创建一个
TestChatViewController *controller = [[TestChatViewController alloc] initWithChatModel:chatModel];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
navigationController.modalPresentationStyle = UIModalPresentationOverFullScreen;
navigationController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:navigationController animated:YES completion:nil];
}
会话页面必须有导航控制器,如果没有控制器,请参考代码示例创建一个。
会话页面 View Controller
在 RCChatViewController 类中,会话页面主要由三个部分组成:
| 属性名称 | 类型 | 描述 |
|---|---|---|
headerView | RCChatHeaderView | UI 组件,聊天视图的导航头部,基于系统导航实现。 |
listView | RCMessageListView | UI 组件,显示消息的列表视图。 |
inputBar | RCInputBar | UI 组件,用于输入消息的输入面板。 |
viewModel | RCChatViewModel | 与此 ViewController 关联的 ViewModel。 |
config | RCChatViewConfig | 会话页面聊天视图的配置类。会话页面中部分样式与行为受 Global IM UIKit 全局配置影响。如需了解全局配置,参见 [UIKit 配置指南]。 |
视图结构如下:
定制导航栏
Global IM UIKit 的 RCChatViewController 使用了系统的导航栏,RCChatHeaderView 继承于 RCBaseHeaderView,用于配置导航条属性。
修改导航栏按钮
RCChatHeaderView 有两个默认属性:
/// 左侧按钮对应的 BarItem
@property (nonatomic, strong) RCBarItem *backItem;
/// 右侧按钮对应的 BarItem
@property (nonatomic, strong) RCBarItem *moreItem;
-
backItem对应的左侧按钮会显示会话名称和头像,点击会退出当前页面。支持提示连接状态和输入状态变化提示。 -
moreItem对应的右侧按钮,点击会弹出更多操作菜单:- 开启或关闭通知:设置当前会话通知提醒
- 搜索:SDK 抛出点击事件
didClickSearchBarItem,您可以重写方法自己处理 - 删除消息:清除当前会话的所有消息