【问题标题】:Implementation of comment system (Facebook like)评论系统的实施(Facebook赞)
【发布时间】:2017-06-06 13:02:48
【问题描述】:

我正在寻找一种创建评论系统的方法,该系统的行为类似于 Facebook 的帖子评论部分。

现在我有这个结构:

但我还需要实现对 cme​​ts 的回复和对回复的回复等等。 应该怎么做才能实现与 Facebook 相同的行为?

【问题讨论】:

  • 如果有帮助,你需要接受答案,让其他人更快找到它。

标签: ios swift uitableview uikit


【解决方案1】:

要实现滑动到replydelete 和其他东西,使用这个库: 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)
}

这样。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-30
    • 2010-10-01
    • 2013-01-22
    • 2012-03-01
    • 2016-02-22
    • 2013-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多