如何在一个tableView上提供两个以上的自定义单元格进行聊天 [英] How to give more than 2 custom cell on one tableView for chat
本文介绍了如何在一个tableView上提供两个以上的自定义单元格进行聊天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
聊天ui的聊天图像有3种类型,分别是text,image和carousel。我需要为一个tableView制作3个自定义单元格吗?如何做到这一点?
chat image for chat ui have 3 type which is text , image , and carousel . am i need to make 3 custom cell for one tableView and how to do that ?
推荐答案
是的必须创建三个自定义单元格,以供第三方使用,也可以在tableview单元格内使用集合视图。
Yes you have to create three custom cell, for crousal either use third party or a collection view inside tableview cell.
例如:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIncomming = tableView.dequeueReusableCell(withIdentifier: "IncommingChatCell") as! IncommingChatCell
let cellOutgoing = tableView.dequeueReusableCell(withIdentifier: "OutgoingChatCell") as! OutgoingChatCell
let chatInfo = chatDataSourse[indexPath.row]
if chatInfo.user == "receiver" {
cellIncomming.chatLabel.text = chatInfo.chatString
return cellIncomming
}else {
cellOutgoing.chatLabel.text = chatInfo.chatString
return cellOutgoing
}
}
这篇关于如何在一个tableView上提供两个以上的自定义单元格进行聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文