【发布时间】:2019-06-09 14:17:30
【问题描述】:
当我调用将 ViewController 推送到详细聊天控制器(一对一聊天)时,我有以下代码。但是,如果我点击太快,视图控制器将被推送两次。动画看了两遍。谁能指出错误在哪里?代码来自 LBTA 的 Youtube 课程(Firebase 聊天)。
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)
}
【问题讨论】:
标签: ios swift uitableview uinavigationcontroller