Contacts Page
This feature is supported starting from version 5.12.0.
The Contacts page displays all friends of the current user on the device. Upon entering this page, the IMKit SDK retrieves friend information from the database and sorts it alphabetically by friend name (displaying the alias if available).
IMKit provides RCFriendListViewController
, a contacts page class based on UIKit's UITableView
.
The Contacts page typically consists of three components: a navigation bar, search bar, and contacts list. The first section of the contacts list supports custom functions such as "New Friends" or "Current User".

Initialization
Initialize the Contacts page by calling the constructor of RCFriendListViewController
.
Note: You need to create an RCFriendListViewModel
object as the business logic handler for RCFriendListViewController
.
Parameters
Parameter | Type | Description |
---|---|---|
viewModel | RCFriendListViewModel | The business logic handler for RCFriendListViewController . Manages UI configuration and friend data retrieval. |
Sample Code
RCFriendListViewModel *viewModel = [[RCFriendListViewModel alloc] init];
RCFriendListViewController *contactVC = [[RCFriendListViewController alloc] initWithViewModel:viewModel];
[self.navigationController pushViewController:contactVC animated:YES];
Customization
The IMKit Contacts interface supports extensive customization.
Custom Navigation Bar
RCFriendListViewController
uses the system navigation bar to display the page title. Override RCFriendListViewController
and set the title
property in viewDidLoad
to customize.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"New Title";
}
Custom Search Bar
By default, RCFriendListViewController
searches contacts. Implement delegate methods via RCFriendListViewModel
's delegate
property to customize search functionality.
Sample Code
RCFriendListViewModel *viewModel = [[RCFriendListViewModel alloc] init];
viewModel.delegate = self;
RCFriendListViewController *contactVC = [[RCFriendListViewController alloc] initWithViewModel:viewModel];
[self.navigationController pushViewController:contactVC animated:YES];
...
/// Configure custom search functionality
- (RCSearchBarViewModel *_Nullable)willConfigureSearchBarViewModelForFriendListViewModel:(RCFriendListViewModel *)viewModel {
// Return custom search ViewModel
}
...
Custom Contacts List Cell
1. Create RCCustomCell
@interface RCCustomCell : UITableViewCell
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@end
@implementation
// Cell rendering
@end
2. Create RCCustomCellViewModel
Custom CellViewModel must inherit from RCFriendListCellViewModel
.
typedef void(^RCPermanentCellViewModelBlock)(UIViewController *);
@interface RCCustomCellViewModel : RCFriendListCellViewModel
/// Constructor
- (instancetype)initWithTitle:(NSString *)title
portrait:(UIImage *)portrait
touchBlock:(RCPermanentCellViewModelBlock)touchBlock;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, strong) UIImage *portrait;
@property (nonatomic, copy) RCPermanentCellViewModelBlock touchBlock;
@end
@implementation RCCustomCellViewModel
- (instancetype)initWithTitle:(NSString *)title
portrait:(UIImage *)portrait
touchBlock:(RCPermanentCellViewModelBlock)touchBlock{
self = [super init];
if (self) {
self.title = title;
self.portrait = portrait;
self.touchBlock = touchBlock;
}
return self;
}
// Register and customize cell
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = @"RCCustomCellIdentifier";
// Register cell
[tableView registerClass:RCCustomCell.class forCellReuseIdentifier:cellIdentifier];
// Return cell
RCCustomCellViewModel *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
// Modify UI
cell.titleLabel.text = self.title;
cell.contentLabel.text = self.detail;
return cell;
}
@end
3. Set RCFriendListViewModel Delegate
Set the delegate when initializing RCFriendListViewModel
:
RCFriendListViewModel *viewModel = [[RCFriendListViewModel alloc] init];
viewModel.delegate = self;
4. Modify Data Source
Implement delegate methods:
// Contacts data source
- (NSArray *_Nullable)friendListViewModel:(RCFriendListViewModel *)viewModel
willLoadItemsInDataSource:(NSArray *_Nullable)dataSource {
// Process data source (add/remove/modify)
}
// Permanent cells for section == 1
- (NSArray <RCFriendListPermanentCellViewModel *>*_Nullable)appendPermanentCellViewModelsForFriendListViewModel:(RCFriendListViewModel *)viewModel {
NSMutableArray *list = dataSource.mutableCopy;
RCCustomCellViewModel *customCellVM = [[RCCustomCellViewModel alloc] initWithTitle:@"title" portrait:[UIImage imageNamed:@"newFriend"] touchBlock:^(UIViewController * vc) {
// Click handler
}];
[list addObject:@[customCellVM]];
return list;
}
5. Custom Cell Tap Event
/// Configure custom tap events. Returns: Whether the app handles the event [YES: SDK skips handling, NO: SDK handles]
- (BOOL)friendListViewModel:(RCFriendListViewModel *)viewModel
viewController:(UIViewController*)viewController
tableView:(UITableView *)tableView
didSelectRow:(NSIndexPath *)indexPath
cellViewModel:(RCBaseCellViewModel *)cellViewModel {
}