CreateConversationVC screen.
Overview
TheCreateConversation component enables users to:
- Browse CometChat users and groups via native list components
- Search within users and groups
- Toggle between “Users” and “Groups” tabs using a segmented control
- Swipe between lists with a
UIPageViewController - Navigate to
MessagesVCupon selecting a user or group
Prerequisites
Before implementing this feature, ensure you have:- Completed Getting Started setup
- CometChat UIKit v5+ installed via CocoaPods or Swift Package Manager
- User authenticated with
CometChatUIKit.login()before presenting this screen - A
UINavigationControllerembedded in your flow MessagesVCimplemented to handle chat screens
Components
| Component | Description |
|---|---|
UISegmentedControl | Switches between “Users” and “Groups” tabs |
UIPageViewController | Enables swipe navigation between list views |
CometChatUsers | Displays the list of CometChat users |
CometChatGroups | Displays the list of CometChat groups |
MessagesVC | Chat interface, launched upon item selection |
searchController | Provides search for both users and groups |
CometChatTheme | Applies theming (colors, fonts) for UI consistency |
CometChatTypography | Defines text styles for segment labels |
Integration Steps
Step 1: Present the Create Conversation Screen
PushCreateConversations to allow starting a chat:
HomeScreenViewController.swift
Step 2: Set Up the User Interface
Build the segmented control and page view controller:CreateConversations.swift
Step 3: Configure Segmented Control Navigation
Toggle between user and group lists when the segment changes:CreateConversations.swift
Step 4: Handle Item Selection
Navigate toMessagesVC when a user or group is tapped:
CreateConversations.swift
Step 5: Manage Page View Transitions
Implement data source and delegate for smooth swiping:CreateConversations.swift
Customization Options
Segment Styling
UseCometChatTheme to customize tint and font:
Labels
Localize or rebrand “USERS” / “GROUPS” labels:Search
AdjustsearchController.placeholder and styling:
Edge Cases
| Scenario | Handling |
|---|---|
| Live search | Built-in in CometChatUsers and CometChatGroups |
| Empty states | Components display default “no results” views |
| Segment disabled | Hide tabs if only one list is relevant |
Error Handling
| Error Type | Solution |
|---|---|
| Load errors | Use setErrorView() on list components |
| Navigation failures | Present an alert if push fails |
| Blocked users | Intercept in onItemClick to prevent navigation |
Feature Matrix
| Feature | Implementation |
|---|---|
| Show create screen | showCreateConversation() |
| Tabbed lists | UISegmentedControl + UIPageViewController |
| Display users | CometChatUsers() |
| Display groups | CometChatGroups() |
| Search functionality | searchController |
| Navigate to chat | MessagesVC(user:) / MessagesVC(group:) |
Related Components
- Users - Display user list
- Groups - Display group list
- Conversations - Display conversation list