-2
我正在寻找一种创建评论系统的方式,其行为类似Facebook的发表评论部分。评论系统的实现(Facebook like)
现在我有这样的结构:
但我也需要落实答复的意见和回复的回复等等。 应该做些什么来达到与Facebook相同的行为?
我正在寻找一种创建评论系统的方式,其行为类似Facebook的发表评论部分。评论系统的实现(Facebook like)
现在我有这样的结构:
但我也需要落实答复的意见和回复的回复等等。 应该做些什么来达到与Facebook相同的行为?
要实现刷卡到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)
}
像那。
希望它有帮助
如果有帮助,您需要接受答案,让其他人更快地找到答案。 –