2017-06-06 96 views
-2

我正在尋找一種創建評論系統的方式,其行爲類似Facebook的發表評論部分。評論系統的實現(Facebook like)

現在我有這樣的結構:

Structure

但我也需要落實答覆的意見和回覆的回覆等等。 應該做些什麼來達到與Facebook相同的行爲?

+0

如果有幫助,您需要接受答案,讓其他人更快地找到答案。 –

回答

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) 
} 

像那。

希望它有幫助