答案 0 :(得分: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)
}
就像那样。
希望有所帮助