• UIKit
  • SDK
  • 서버 API
Chat/
UIKit/
iOS and macOS/
Build Basic Interfaces/
UIKit
  • 개요
  • Run Demo
  • 시작
  • 설치
    • TUIKit
    • TUIChat만
  • Build Basic Interfaces
    • Chat
    • Conversation List
    • Contact List
    • Add Contact
    • Create Group Chat
    • Video and Audio Call
  • Features
    • 반응
    • Quote
    • 읽음 확인
    • 사용자 온라인 상태
    • Translation
    • Voice to Text
    • 메시지 검색
  • 맞춤화
    • 메시지 맞춤화
    • 이모티콘과 스티커 맞춤화
  • 현지화
  • Changelog
  • Guideline for Beginners
  • 콘솔 안내
    • 애플리케이션 생성 및 업그레이드
    • 기본 구성
    • 기능 구성
    • 계정 관리
    • 그룹 관리
    • 콜백 구성
  • 제품 소개
    • 메시지 관리
      • 1대1 메시지
      • 메시지 저장
      • 오프라인 푸시
      • 그룹 메시지
      • 메시지 포맷
    • 계정 시스템
      • 로그인 인증
      • 온라인 상태 관리
    • 그룹 관련
      • 그룹 시스템
      • 그룹 관리
    • 사용자 정보 및 관계망
      • 정보 관리
      • 관계망 관리
  • 구매 가이드
    • 과금 개요
    • 가격
  • 에러코드
이 페이지는 현재 영어로만 제공되며 한국어 버전은 곧 제공될 예정입니다. 기다려 주셔서 감사드립니다.

Conversation List

This article will guide you through the process of building a conversation list interface.

Display Effect

The effect of the conversation list is shown below:



Environment Requirements

Xcode 10 or later
iOS 9.0 or later

Preconditions

Before building the interface, please ensure that you have completed the following 4 things:
1. Created an application in the console.
2. Created some user accounts in the console.
3. Integrated with TUIKit or TUIConversation.
4. Called the login API in TUILogin to log in to the component.
Note:
1. All components use this API to log in. You can log in once every time you start the application.
2. Please make sure that the login is successful, and we recommend that you do the following in the callback of successful login.
If you haven't completed the above 4 steps, please refer to the corresponding steps in Getting Started first, otherwise you may encounter obstacles when implementing the following features.
If you have already completed them, please continue reading below.

Step Instructions

Building a conversation list usually involves the following 3 steps:
1. Load the conversation list. The list corresponds to the TUIConversationListController object. After loading, TUIConversationListController will automatically retrieve recent conversations.
2. When a user clicks on a row in the conversation list, TUIConversationListController will trigger the didSelectConversation event.
3. Respond to the click in didSelectConversation, which is usually to enter the chat interface of that conversation.
Sample code:
Minimalist version
Classic version
#import "TUIConversationListController_Minimalist.h"
#import "TUIBaseChatViewController_Minimalist.h"
#import "TUIGroupChatViewController_Minimalist.h"
#import "TUIC2CChatViewController_Minimalist.h"

// ConversationController is your own ViewController
@implementation ConversationController
- (void)viewDidLoad {
[super viewDidLoad];
// TUIConversationListController_Minimalist
TUIConversationListController_Minimalist *vc = [[TUIConversationListController_Minimalist alloc] init];
vc.delegate = self;
// Option 1: push vc.
[self.navigationController pushViewController:vc animated:YES];
// Option 2: Add TUIConversationListController_Minimalist to your own ViewController
// [self addChildViewController:vc];
// [self.view addSubview:vc.view];
}

- (void)conversationListController:(TUIConversationListController_Minimalist *)conversationController
didSelectConversation:(TUIConversationCellData *)conversation {
// Conversation list click event, typically, opening the chat UI
TUIChatConversationModel *conversationData = [TUIChatConversationModel new];
conversationData.userID = conversation.userID;
conversationData.title = conversation.title;
conversationData.faceUrl = conversation.faceUrl;
// Create chatVC by groupID or userID.
TUIBaseChatViewController_Minimalist *chatVC = nil;
if (conversationData.groupID.length > 0) {
chatVC = [[TUIGroupChatViewController_Minimalist alloc] init];
} else if (conversationData.userID.length > 0) {
chatVC = [[TUIC2CChatViewController_Minimalist alloc] init];
}
chatVC.conversationData = conversationData;
// Option 1: push chatVC.
[self.navigationController pushViewController:chatVC animated:YES];
// Option 2: add chatVC to your own ViewController.
// [self addChildViewController:vc];
// [self.view addSubview:vc.view];
}

@end
#import "TUIConversationListController.h"
#import "TUIBaseChatViewController_Minimalist.h"
#import "TUIGroupChatViewController.h"
#import "TUIC2CChatViewController.h"

// ConversationController is your own ViewController
@implementation ConversationController
- (void)viewDidLoad {
[super viewDidLoad];
// TUIConversationListController
TUIConversationListController *vc = [[TUIConversationListController alloc] init];
vc.delegate = self;
// Option 1: push vc.
[self.navigationController pushViewController:vc animated:YES];
// Option 2: Add TUIConversationListController to your own ViewController
// [self addChildViewController:vc];
// [self.view addSubview:vc.view];
}

- (void)conversationListController:(TUIConversationListController *)conversationController
didSelectConversation:(TUIConversationCellData *)conversation {
// Conversation list click event, typically, opening the chat UI
TUIChatConversationModel *conversationData = [TUIChatConversationModel new];
conversationData.userID = conversation.userID;
conversationData.title = conversation.title;
conversationData.faceUrl = conversation.faceUrl;
// Create chatVC by groupID or userID.
TUIBaseChatViewController *chatVC = nil;
if (conversationData.groupID.length > 0) {
chatVC = [[TUIGroupChatViewController alloc] init];
} else if (conversationData.userID.length > 0) {
chatVC = [[TUIC2CChatViewControlleralloc] init];
}
chatVC.conversationData = conversationData;
// Option 1: push chatVC.
[self.navigationController pushViewController:chatVC animated:YES];
// Option 2: add chatVC to your own ViewController.
// [self addChildViewController:vc];
// [self.view addSubview:vc.view];
}

@end
Note:
If you haven't sent messages to any person or group before, no conversation will be generated. In this case, loading the TUIConversationListController will show an empty list. For a better experience, it's recommended to send messages to some accounts first to trigger the creation of conversations. If you want to know how to send messages in the chat interface, please refer to the document: Build Chat Interface.

More practices

You can locally run the TUIKitDemo source code to explore more interface implementations.

Contact Us

If you have any questions about this article, feel free to join the Telegram Technical Group, where you will receive reliable technical support.