小编富源V*_*rve的帖子

当我双击太快时 PushViewController 两次

当我调用将 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)

uitableview uinavigationcontroller ios swift

2
推荐指数
1
解决办法
1015
查看次数

标签 统计

ios ×1

swift ×1

uinavigationcontroller ×1

uitableview ×1