跳到主要内容

提示

此功能在 5.12.2 版本开始支持。

我的群组页面

我的群组页面展示了当前用户已加入的群组。进入该页面,SDK 就会从数据库中拉取群组信息。IMKit 提供基于 UITableView 的群组页面类 RCMyGroupsViewController

我的群组页面

我的群组页面一般由导航栏,搜索栏和群组列表三部分部分组成。

初始化

调用 RCMyGroupsViewController 类的初始化方法构建列表页面。注意,您需要创建一个 RCMyGroupsViewModel 对象, 作为RCMyGroupsViewController 的业务逻辑处理模块。


RCMyGroupsViewModel *viewModel = [[RCMyGroupsViewModel alloc] init];
RCMyGroupsViewController *vc = [[RCMyGroupsViewController alloc] initWithViewModel:viewModel];
[self.navigationController pushViewController:vc animated:YES];
参数类型说明
viewModelRCMyGroupsViewModelRCMyGroupsViewController 的业务逻辑处理模块。 处理页面UI的配置以及群组信息的拉取。

定制化

IMKit 群组界面的样式可供自定义修改。

标题栏

IMKit 的 RCMyGroupsViewController 使用了系统的导航栏,可用于显示群组的标题,用户通过继承RCMyGroupsViewController ,在 viewDidLoad 方法中通过 title 属性设置标题。

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"新标题";
}

搜索框

RCMyGroupsViewController 搜索框默认是实现跳转到搜索群组页面,通过设置 RCMyGroupsViewModeldelegate 属性, 实现相关代理方法,自定义搜索功能。


RCMyGroupsViewModel *viewModel = [[RCMyGroupsViewModel alloc] init];
viewModel.delegate = self;
RCMyGroupsViewController *vc = [[RCMyGroupsViewController alloc] initWithViewModel:viewModel];

[self.navigationController pushViewController:vc animated:YES];

...

/// 配置自定义的搜索功能
- (RCSearchBarViewModel *_Nullable)willConfigureSearchBarViewModelForMyGroupsViewModel:(RCMyGroupsViewModel *)viewModel {
- //返回自定义的搜索 ViewModel
}

自定义 Cell

1. 自定义 RCCustomCell

@interface RCCustomCell : UITableViewCell
@property (nonatomic, strong) UILabel *titleLabel;
@end

@implementation
// Cell 绘制
@end

2.自定义 RCCustomCellViewModel

提示

RCGroupInfoCellViewModel 可以Cell的创建, 自定义 CellViewModel 需要继承该类


@interface RCCustomCellViewModel : RCGroupInfoCellViewModel
@property (nonatomic, strong) RCGroupInfo *groupInfo;

/// 初始化
/// - keyword: 高亮关键字
- (instancetype)initWithGroupInfo:(RCGroupInfo *)groupInfo
keyword:(NSString *)keyword;

@end

@implementation RCCustomCellViewModel

- (instancetype)initWithGroupInfo:(RCGroupInfo *)groupInfo
keyword:(NSString *)keyword
{
self = [super init];
if (self) {
self.groupInfo = groupInfo;
self.keyword = keyword;
}
return self;
}

// 注册并自定义cell
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = @"RCCustomCellIdentifier";
// 注册 cell
[tableView registerClass:RCCustomCell.class forCellReuseIdentifier:cellIdentifier];
// 返回 cell
RCCustomCellViewModel *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
//修改UI
cell.titleLabel.text = self.groupInfo.groupName;
...
return cell;
}

@end

3. 修改数据源

实现代理方法:

// 数据源
- (NSArray *_Nullable)myGroupsViewModel:(RCMyGroupsViewModel *)viewModel
willLoadItemsInDataSource:(NSArray *_Nullable)dataSource{
// 对数据源增删改处理

}

4.点击 cell

/// 配置自定义点击事件,Returns: App是否处理[YES : SDK不再处理, NO: SDK处理]
- (BOOL)myGroupsViewModel:(RCMyGroupsViewModel *)viewModel
viewController:(UIViewController*)viewController
tableView:(UITableView *)tableView
didSelectRow:(NSIndexPath *)indexPath
cellViewModel:(RCBaseCellViewModel *)cellViewModel {

}