【发布时间】:2018-08-15 12:28:57
【问题描述】:
我正在使用 firebase 在 ios swift 中开发一个聊天应用程序。我能够成功发送和检索消息。
但问题是整个消息要么向右或向左显示。我想在右方向显示发送者消息,在左方向显示接收者消息。使用下面的代码,它可以向左或向右显示所有消息。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellchat:TVCChatTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellchat", for: indexPath) as! TVCChatTableViewCell
cellchat.setChat(chat: listofChatinfo[indexPath.row])
return cellchat
let cell = lachatlist.dequeueReusableCell(withIdentifier: "PostCell")
let uuid = Auth.auth().currentUser?.uid
if uuid == senderid {
cell?.textLabel?.textAlignment = .right
cell?.textLabel?.text = postData[indexPath.row]
}
// cell.setChat
//PostCell.
return cell!
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
【问题讨论】:
-
制作两个细胞,一个是发送者细胞,一个是接收者细胞。 if object confrorms to sender deque sender celll 否则为接收者 cell。
-
你能提供更详细的代码吗?