Search Friends
The Search Friends page allows users to retrieve all friends stored on their current device. Upon entering this page, the IMKit SDK queries friend information from the local database based on keywords entered in the search field.
IMKit provides RCSearchFriendsViewController
, a search page class built on UIKit's UITableView
.
The Search Friends page typically consists of three components:
- Navigation bar
- Search bar
- Friends list

Initialization
Initialize the search friends page by calling the constructor of RCSearchFriendsViewController
.
Note: You need to create an RCSearchFriendsViewModel
object as the business logic handler for RCSearchFriendsViewController
.
Parameter Description
Parameter | Type | Description |
---|---|---|
viewModel | RCSearchFriendsViewModel | The business logic handler for RCSearchFriendsViewController . Manages UI configuration and friend data retrieval. |
Sample Code
RCSearchFriendsViewModel *viewModel = [[RCSearchFriendsViewModel alloc] init];
RCSearchFriendsViewController *vc = [[RCSearchFriendsViewController alloc] initWithViewModel:viewModel];
[self.navigationController pushViewController:vc animated:YES];
Customization
The appearance of IMKit's Search Friends interface can be customized.
Custom Title Bar
IMKit's RCSearchFriendsViewController
uses the system navigation bar to display the page title. To customize the title, subclass RCSearchFriendsViewController
and set the title
property in the viewDidLoad
method.
Sample Code
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"New Title";
}
Custom Search Field
By default, RCSearchFriendsViewController
searches friends. Implement the delegate methods of RCSearchFriendsViewModel
to customize search functionality.
Sample Code
RCSearchFriendsViewModel *viewModel = [[RCSearchFriendsViewModel alloc] init];
viewModel.delegate = self;
RCSearchFriendsViewController *vc = [[RCSearchFriendsViewController alloc] initWithViewModel:viewModel];
[self.navigationController pushViewController:vc animated:YES];
...
/// Configure custom search functionality
- (RCSearchBarViewModel *_Nullable)willConfigureSearchBarViewModelForSearchFriendsViewModel:(RCSearchFriendsViewModel *_Nonnull)viewModel {
// Return custom search ViewModel
}
...
Customize Search Friends Page Cell
1. Create RCCustomCell
@interface RCCustomCell : UITableViewCell
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@end
@implementation RCCustomCell
// Cell rendering
@end
2. Create RCCustomCellViewModel
Custom CellViewModel must subclass RCFriendListCellViewModel
.
typedef void(^RCPermanentCellViewModelBlock)(UIViewController *);
@interface RCCustomCellViewModel : RCFriendListCellViewModel
/// Initializer
- (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";
[tableView registerClass:RCCustomCell.class forCellReuseIdentifier:cellIdentifier];
RCCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
cell.titleLabel.text = self.title;
cell.contentLabel.text = self.detail;
return cell;
}
@end
3. Set RCSearchFriendsViewModel Delegate
Set the delegate when initializing RCSearchFriendsViewModel
:
RCSearchFriendsViewModel *viewModel = [[RCSearchFriendsViewModel alloc] init];
viewModel.delegate = self;
4. Modify Data Source
Implement delegate method:
- (NSArray *_Nullable)searchFriendsViewModel:(RCSearchFriendsViewModel *_Nonnull)viewModel
willLoadItemsInDataSource:(NSArray *_Nullable)dataSource {
NSMutableArray *list = dataSource.mutableCopy;
RCCustomCellViewModel *customCellVM = [[RCCustomCellViewModel alloc]
initWithTitle:@"title"
portrait:[UIImage imageNamed:@"newFriend"]
touchBlock:^(UIViewController *vc) {
// Handle tap event
}];
[list addObject:@[customCellVM]];
return list;
}
5. Customize Cell Tap Event
- (BOOL)searchFriendsViewModel:(RCSearchFriendsViewModel *_Nonnull)viewModel
viewController:(UIViewController*_Nonnull)viewController
tableView:(UITableView *_Nonnull)tableView
didSelectRow:(NSIndexPath *_Nonnull)indexPath
cellViewModel:(RCBaseCellViewModel *_Nonnull)cellViewModel {
// Return YES if handled by app, NO for default SDK handling
}