Skip to main content

Search My Groups

tip

This feature is supported starting from version 5.12.2.

The Search My Groups page allows users to retrieve groups they've joined. Upon entering keywords in the search field, the IMKit SDK fetches group information from the database.
IMKit provides RCSearchGroupsViewController, a search page class based on UITableView.

The Search My Groups page typically consists of three components: a navigation bar, search bar, and group list.

Initialization

Initialize the search groups page by calling the constructor of RCSearchGroupsViewController.
Note: You need to create an RCSearchGroupsViewModel object as the business logic handler for RCSearchGroupsViewController.

Parameter Description

ParameterTypeDescription
viewModelRCSearchGroupsViewModelThe business logic handler for RCSearchGroupsViewController. Manages UI configuration and group information retrieval.

Sample Code

RCSearchGroupsViewModel *viewModel = [[RCSearchGroupsViewModel alloc] init];
RCSearchGroupsViewController *vc = [[RCSearchGroupsViewController alloc] initWithViewModel:viewModel];
[self.navigationController pushViewController:vc animated:YES];

Customization

The UI of IMKit's Search My Groups page can be customized.

Customizing the Title Bar

IMKit's RCSearchGroupsViewController uses the system navigation bar to display the page title. By subclassing RCSearchGroupsViewController, you can set the title via the title property in the viewDidLoad method.

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"New Title";
}

By default, RCSearchGroupsViewController searches groups by name. To implement custom search functionality, set the delegate property of RCSearchGroupsViewModel and implement the corresponding delegate methods.

Sample Code

RCSearchGroupsViewModel *viewModel = [[RCSearchGroupsViewModel alloc] init];
viewModel.delegate = self;
RCSearchGroupsViewController *vc = [[RCSearchGroupsViewController alloc] initWithViewModel:viewModel];

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

...

/// Configure custom search functionality
- (RCSearchBarViewModel *_Nullable)willConfigureSearchBarViewModelForSearchGroupsViewModel:(RCSearchGroupsViewModel *_Nonnull)viewModel{
// Return a custom search ViewModel
}

...

Customizing Group Cell

1. Create a Custom Cell

@interface RCCustomCell : RCFriendListPermanentCell
- (void)showPortrait:(NSString *)url;
@end

@implementation
// Cell rendering logic
@end

2. Create a Custom CellViewModel

tip

Custom CellViewModels must subclass RCGroupInfoCellViewModel.

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

/// Initializer
/// - Parameters:
/// - groupInfo: Group information
/// - keyword: Highlighted keyword
- (instancetype)initWithGroupInfo:(RCGroupInfo *)groupInfo
keyword:(NSString *)keyword;
@end

// Register and customize the cell
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = @"RCCustomCellIdentifier";
// Register cell
[tableView registerClass:RCCustomCell.class forCellReuseIdentifier:cellIdentifier];
// Dequeue cell
RCCustomCellViewModel *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
// Modify UI
...
return cell;
}
@end

3. Modify Data Source

Implement the data source callback method:

// Group data source
- (NSArray *_Nullable)searchGroupsViewModel:(RCSearchGroupsViewModel *_Nonnull)viewModel
willLoadItemsInDataSource:(NSArray *_Nullable)dataSource {
// Process data source (add/remove/modify)
NSMutableArray *list = dataSource.mutableCopy;
RCCustomCellViewModel *customCellVM = [[RCCustomCellViewModel alloc] initWithGroupInfo:"group" keyword:"keyword"];
[list addObject:@[customCellVM]];
return list;
}

4. Customize Cell Tap Event

/// Handle cell tap events
/// - Parameters:
/// - viewModel: viewModel
/// - viewController: viewController
/// - tableView: tableView
/// - indexPath: indexPath
/// - viewModel: CellViewModel
/// - Returns: Whether the app handles the event [YES: SDK skips default handling, NO: SDK processes it]
///
/// - Since: 5.12.2
- (BOOL)searchGroupsViewModel:(RCSearchGroupsViewModel *_Nonnull)viewModel
viewController:(UIViewController*_Nonnull)viewController
tableView:(UITableView *_Nonnull)tableView
didSelectRow:(NSIndexPath *_Nonnull)indexPath
cellViewModel:(RCBaseCellViewModel *_Nonnull)cellViewModel {
}