ios - 如何在一个 tableView 上提供 2 个以上的自定义单元格进行聊天

标签 ios swift uitableview chat custom-cell

用于聊天 ui 的聊天图像有 3 种类型,即文本、图像和旋转木马。我需要为一个 tableView 制作 3 个自定义单元格吗?该怎么做?

/image/tVt9j.png

最佳答案

是的,您必须创建三个自定义单元格,以便使用第三方或 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/

相关文章:

ios swift类符合协议(protocol)

ios - Realm:如何获取数据库的当前大小

swift - UITableViewCell 子类单元格中的错误图像或旧图像错误

iphone - sqlite3 和 fmdb 嵌套 FMResultSet 是可能的吗?

ios - UIScrollView:仅在允许时滚动

ios - 调度组通知似乎被调用得太早

swift - 对 TableView 行进行排序

ios - View 模型应该对 View Controller 中的事件使用react吗?

ios - 自定义 AVVideoCompositing 类未按预期工作

UITableView 多对勾选择