如何给超过2自定义单元格在一个的tableView聊天

问题描述 投票:0回答:2

聊天UI聊天图像具有3型是文本,图像,和转盘。我我需要做3自定义单元格为一个的tableView以及如何做到这一点?

ios swift uitableview chat custom-cell
2个回答
2
投票

是的,你必须创建三个自定义细胞,旋转木马或者使用第三方或tableview中细胞内的CollectionView。

对于例如:

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
投票

在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
}
© www.soinside.com 2019 - 2024. All rights reserved.