Внедрение системы комментариев (как в Facebook)

-2

Я ищу способ создать систему комментариев, которая ведет себя как раздел комментариев в Facebook.

Прямо сейчас у меня есть эта структура:

Изображение 174551

Но мне нужно также выполнить ответы на комментарии и ответы на ответы и так далее. Что нужно сделать, чтобы добиться такого же поведения в Facebook?

  • 0
    Если это помогло, вам нужно принять ответ, чтобы другие быстрее его нашли.
Теги:
uitableview
uikit

1 ответ

1
Лучший ответ

Чтобы реализовать салфетки для reply или delete и другие вещи, используйте эту библиотеку: MGSwipeTableCell

Для ответа и удаления выполните следующие действия:

private func addFuncButtons(to cell: CommentCell, at row: Int) {
  let currentUserId = User.getCurrentUserId()

  if (cell.comment.userId == currentUserId // if its current user comment
     || userId! == currentUserId) // if current user is post author
     && cell.comment.key != "" { // cant delete desc
     cell.rightButtons = [
        MGSwipeButton(title: "", icon: UIImage(named:"delete.png"), backgroundColor: .red) {
           (sender: MGSwipeTableCell!) -> Bool in
           self.removeCell(cell, at: row)
           return true
        },
        MGSwipeButton(title: "", icon: UIImage(named:"reply.png"), backgroundColor: .darkGray) {
           (sender: MGSwipeTableCell!) -> Bool in
           self.replyToUser(with: cell.userNickName.currentTitle!)
           return true
        }
     ]
  } else {
     // add only reply button
     cell.rightButtons = [
        MGSwipeButton(title: "", icon: UIImage(named:"reply.png"), backgroundColor: .darkGray) {
           (sender: MGSwipeTableCell!) -> Bool in
           self.replyToUser(with: cell.userNickName.currentTitle!)
           return true
        }
     ]
  }

  cell.rightSwipeSettings.transition = .rotate3D
}

Действия:

private func removeCell(_ cell: CommentCell, at row: Int) {
  removeCellFromTable(cell, at: row)
  removeCellFromDataBase(cell)
}

private func removeCellFromTable(_ cell: CommentCell, at row: Int) {
   comments.remove(at: row)
   tableView.reloadData()
}

private func removeCellFromDataBase(_ cell: CommentCell) {
   Comment.remove(cell.comment, from: post)
}

private func replyToUser(with login: String) {
   newCommentTextField.text = newCommentTextField.text?.appending(" @" + login)
}

Как это.

Надеюсь, поможет

Ещё вопросы

Сообщество Overcoder
Наверх
Меню