How to give more than 2 custom cell on one tableView for chat

岁酱吖の 提交于 2019-12-13 03:45:32

问题


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 ?


回答1:


Yes you have to create three custom cell, for crousal either use third party or a collection view inside tableview cell.

for eg:

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
  }
}



回答2:


in cellforrow

if Condition1 {
    let cell : CellOne! = tableView.dequeueReusableCell( withIdentifier: "CellOne") as? CellOne
    return cell
}else if Condition2{
    let cell : CellTwo! = tableView.dequeueReusableCell( withIdentifier: "CellTwo") as? CellTwo
    return cell
}else{
    let cell : CellThree! = tableView.dequeueReusableCell( withIdentifier: "CellThree") as? CellThree
    return cell
}


来源:https://stackoverflow.com/questions/54642655/how-to-give-more-than-2-custom-cell-on-one-tableview-for-chat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!