问题
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