Overview
TheCreateConversation
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
MessagesVC
upon selecting a user or group.
Prerequisites
- A UIKit-based iOS project.
- CometChat UIKit for iOS v5 installed via CocoaPods or Swift Package Manager.
- User authenticated with
CometChat.login()
before presenting this screen. - A
UINavigationController
embedded in your flow. MessagesVC
implemented to handle chat screens.
Components
Component | Role |
---|---|
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
1. Presenting the Create Conversation Screen
PushCreateConversations
to allow starting a chat.
HomeScreenViewController.swift
Provides entry point to the create-conversation flow.
2. Setting Up the User Interface
Build the segmented control and page view controller.CreateConversations.swift
Initializes the UI elements and search integration.
3. Configuring Segmented Control Navigation
Toggle between user and group lists when the segment changes.CreateConversations.swift
Keeps the proper search bar and view in sync with the selected tab.
4. Handling Item Selection
Navigate toMessagesVC
when a user or group is tapped.
CreateConversations.swift
Routes the user to the appropriate chat screen.
5. Managing Page View Transitions
Implement data source and delegate for smooth swiping.CreateConversations.swift
Synchronizes the segmented control with page swipes.
Customization Options
- Segment Styling: Use
CometChatTheme
to customize tint and font. - Labels: Localize or rebrand “USERS” / “GROUPS” labels.
- Search: Adjust
searchController.placeholder
and styling.
Filtering & Edge Cases
- Live Search: Built-in in
CometChatUsers
andCometChatGroups
. - Empty States: Components display default “no results” views.
- Segment Disabled: Hide tabs if only one list is relevant.
Error Handling
- 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:) |
Full Sample App
Explore the complete create-conversation flow:
GitHub → SampleApp
UIKit Source Code
Browse the source for
CreateConversationVC
:
GitHub → CreateConversationVC.swift