当我调用将 ViewController 推送到详细聊天控制器(一对一聊天)时,我有以下代码。但是,如果我点击得太快,视图控制器将被推送两次。我看了两次动画。谁能指出我的错误在哪里?该代码来自 LBTA 的 Youtube 课程 (Firebase Chat)。
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let message = messages[indexPath.row]
guard let chatPartnerId = message.chatPartnerId() else {return}
let ref = Database.database().reference().child("users").child(chatPartnerId)
ref.observeSingleEvent(of: .value, with: { (snapshot) in
guard let dictionary = snapshot.value as? [String: AnyObject] else {
return
}
let user = ChatUser(dictionary: dictionary)
user.id = chatPartnerId
self.showChatControllerForUser(user)
}, withCancel: nil)
}
func showChatControllerForUser(_ user: ChatUser) {
let chatLogController = ChatLogController(collectionViewLayout: UICollectionViewFlowLayout())
chatLogController.chatUser = user
navigationController?.pushViewController(chatLogController, animated: true) …Run Code Online (Sandbox Code Playgroud)