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 ?
Asked
Active
Viewed 433 times
-1
-
same as you do for single cell – SPatel Feb 12 '19 at 04:14
-
1Hope this will help you [UITableview with more than One Custom Cells with Swift](https://stackoverflow.com/questions/30774671/uitableview-with-more-than-one-custom-cells-with-swift) – prex Feb 12 '19 at 04:15
-
hi , thanks for answer . i will try – amaulana Feb 12 '19 at 04:50
2 Answers
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
}

Yogesh Tandel
- 1,738
- 1
- 19
- 25
2
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
}
}

Yogita J
- 181
- 1
- 6
-
-
-
{ "result": { "output": [ { "type": "text", "text": "Ini respons berbentuk teks", "speech": "Ini respons berbentuk teks" }, { "type": "text", "text": "Ini adalah teks yang dipakai sebagai dummy response untuk message type text", "speech": "Ini adalah teks yang dipakai sebagai dummy response untuk message type text" } ] } } – amaulana Feb 13 '19 at 03:13
-
Hi @amaulana tell your backend guys to provide anything(eg: userId or the sender/receiver etc), so that you can recognize that the chat comes from which side. In the above json i can not see any way to set chat bubbles. – Yogita J Feb 13 '19 at 05:27