
TUIKit 或 TUIConversation。TUILogin 的 login 接口登录组件。TUIConversationListController 对象。加载后,TUIConversationListController 会自动读取最近会话。TUIConversationListController 会抛出 didSelectConversation 事件。didSelectConversation 中响应点击,通常是进入该会话的聊天界面。import UIKit// ConversationController is your own ViewControllerclass ConversationController: UIViewController {override func viewDidLoad() {super.viewDidLoad()// TUIConversationListController_Minimalistlet vc = TUIConversationListController_Minimalist()vc.delegate = self// Option 1: push vc.navigationController?.pushViewController(vc, animated: true)// Option 2: Add TUIConversationListController_Minimalist to your own ViewController// addChild(vc)// view.addSubview(vc.view)}}extension ConversationController: TUIConversationListControllerListener {func conversationListController(_ conversationController: UIViewController, didSelectConversation conversation: TUIConversationCellData) -> Bool{// Conversation list click event, typically, opening the chat UIlet conversationData = TUIChatConversationModel()conversationData.userID = conversation.userIDconversationData.title = conversation.titleconversationData.faceUrl = conversation.faceUrl// Create chatVC by groupID or userID.var chatVC: TUIBaseChatViewController_Minimalist?if let groupID = conversationData.groupID, !groupID.isEmpty {chatVC = TUIGroupChatViewController_Minimalist()} else if let userID = conversationData.userID, !userID.isEmpty {chatVC = TUIC2CChatViewController_Minimalist()}chatVC?.conversationData = conversationData// Option 1: push chatVC.navigationController?.pushViewController(chatVC!, animated: true)// Option 2: add chatVC to your own ViewController.// addChild(chatVC!)// view.addSubview(chatVC!.view)}}
#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_MinimalistTUIConversationListController_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 *)conversationControllerdidSelectConversation:(TUIConversationCellData *)conversation {// Conversation list click event, typically, opening the chat UITUIChatConversationModel *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 UIKit// ConversationController is your own ViewControllerclass ConversationController: UIViewController {override func viewDidLoad() {super.viewDidLoad()// TUIConversationListControllerlet vc = TUIConversationListController()vc.delegate = self// Option 1: push vc.navigationController?.pushViewController(vc, animated: true)// Option 2: Add TUIConversationListController to your own ViewController// addChild(vc)// view.addSubview(vc.view)}}extension ConversationController: TUIConversationListControllerListener {func conversationListController(_ conversationController: UIViewController, didSelectConversation conversation: TUIConversationCellData) -> Bool{// Conversation list click event, typically, opening the chat UIlet conversationData = TUIChatConversationModel()conversationData.userID = conversation.userIDconversationData.title = conversation.titleconversationData.faceUrl = conversation.faceUrl// Create chatVC by groupID or userID.var chatVC: TUIBaseChatViewController?if let groupID = conversationData.groupID, !groupID.isEmpty {chatVC = TUIGroupChatViewController()} else if let userID = conversationData.userID, !userID.isEmpty {chatVC = TUIC2CChatViewController()}chatVC?.conversationData = conversationData// Option 1: push chatVC.navigationController?.pushViewController(chatVC!, animated: true)// Option 2: add chatVC to your own ViewController.// addChild(chatVC!)// view.addSubview(chatVC!.view)}}
#import "TUIConversationListController.h"#import "TUIBaseChatViewController_Minimalist.h"#import "TUIGroupChatViewController.h"#import "TUIC2CChatViewController.h"// ConversationController is your own ViewController@implementation ConversationController- (void)viewDidLoad {[super viewDidLoad];// TUIConversationListControllerTUIConversationListController *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 *)conversationControllerdidSelectConversation:(TUIConversationCellData *)conversation {// Conversation list click event, typically, opening the chat UITUIChatConversationModel *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
TUIConversationListController ,列表为空。为了体验效果,建议您先给一些账号发送消息,触发会话的产生。如果您想了解如何在聊天界面发送消息,请参考文档:构建聊天界面。文档反馈