通过设置某种标志隐藏 imageView 和 Label

Hide imageView and Label by setting some kind of flag

如果消息来自同一个用户,你们能帮我隐藏图片和名字吗...我只想在第一条消息中显示它...如果该用户发送更多信息则不要发送给显示直到另一个 ID 出现...就像 whatsapp 一样..

目前我想用这个来给你举个例子 [![在此处输入图片描述][1]][1]

var isTheSameUser = false

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let selectedChat = chat[indexPath.row]
    let myId = String(describing:UserDefaults.standard.value(forKey: "user_id")!)
    let messageUserId = String(describing:selectedChat.owner_id)

    if messageUserId == myId {
        return myMessageCell(indexPath: indexPath)
    }else {
        return userMessageCell(indexPath: indexPath)
    }
}




func myMessageCell(indexPath :IndexPath) -> UITableViewCell {
    let cell = self.mainTableView.dequeueReusableCell(withIdentifier: "MyMessageTableViewCell", for: indexPath) as! MyMessageTableViewCell
    let selectedChat = self.chat[indexPath.row]
    let myId = String(describing:UserDefaults.standard.value(forKey: "user_id")!)

    // Show only for the first message
    // photo image
    if !isTheSameUser {
        cell.profileImageView.isHidden = false
        cell.profileNameLabel.isHidden = false

    } else {
        cell.profileImageView.isHidden = true
        cell.profileNameLabel.isHidden = true
    }

    if let userInfo = getUserMemberOf(userId: messageUserId) {

        cell.profileImageView.imageFromURL(urlString: userInfo["photo"] as! String)
    } else {
        cell.profileImageView.image = #imageLiteral(resourceName: "accountIcon")
    }
    cell.profileNameLabel.text = "\(String(describing: cell.userProfileInfo!["name"]!))"

    return cell

每条消息你都需要查看之前的聊天消息

if indexPath.row != 0 {

   let prevItem = chat[indexPath.row - 1]
   let currentItem = chat[indexPath.row] 
    if prevItem.owner_id! == currentItem.owner_id! {
            // hide label and image
    }else {
        // show them

    }

}
else {
       // show them
}