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)
}
のようにそれ。
希望する場合
助けがあれば、他の人がそれをより早く見つけることができるように、回答を受け入れる必要があります。 –