用于聊天 ui 的聊天图像有 3 种类型,即文本、图像和旋转木马。我需要为一个 tableView 制作 3 个自定义单元格吗?该怎么做?
最佳答案
是的,您必须创建三个自定义单元格,以便使用第三方或 tableview 单元格内的 Collection View 。
例如:
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
}
}
关于ios - 如何在一个 tableView 上提供 2 个以上的自定义单元格进行聊天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54642655/