创建新对话框时没有调用委托方法

时间:2018-01-31 15:30:23

标签: ios swift quickblox

我有一个对话框列表,当新消息发布到现有对话框时,它会按预期更新。

当有人在新对话框中向我发送新消息时(即不在表格视图中的消息),没有任何更新。似乎没有调用委托方法,即使我输入并记录了每个QBChatDelegateQBChatServiceDelegate方法。

我已将其设置为当我转到另一个视图并返回到表视图时,它会手动检索对话框并重新加载表视图。我需要这个来自动更新。

我错过了什么?

编辑:当前登录用户以外的人创建新对话框时应触发哪种委托方法?

编辑:更多上下文的一些代码...

在我的课程中,我将其设为QBChatDelegateQBChatServiceDelegate;

QBChat.instance.addDelegate(self) self.chatService.addDelegate(self)

然后我将当前用户登录到QuickBlox;

self.currentUser.blobID = qbUserID
self.currentUser.login = qbUsername
self.currentUser.password = qbPassword

self.services.logIn(with: self.currentUser, completion: { (success, errorMessage) in

    guard success, errorMessage == nil else {
        self.log.error("quickblox: \(errorMessage!)")
        return
    }

    self.chatService.connect(completionBlock: { (error) in
        guard error == nil else {
            self.log.error("chatService.connect: \(error!.localizedDescription)")
            return
        }
    })

})

然后我为QBChatDelegateQBChatServiceDelegate调用每个委托方法;

// QMChatServiceDelegate

func chatService(_ chatService: QMChatService, didAddChatDialogToMemoryStorage chatDialog: QBChatDialog) {
    self.log.info()
    self.notifyOfNewMessage()
    self.delegate?.didCreateDialogs()
}

func chatService(_ chatService: QMChatService, didAddChatDialogsToMemoryStorage chatDialogs: [QBChatDialog]) {
    self.log.info()
    self.notifyOfNewMessage()
    self.delegate?.didCreateDialogs()
}

func chatService(_ chatService: QMChatService, didUpdateChatDialogInMemoryStorage chatDialog: QBChatDialog) {
    self.log.info()
    self.notifyOfNewMessage()
    self.delegate?.didUpdateDialogs([chatDialog])
}

func chatService(_ chatService: QMChatService, didUpdateChatDialogsInMemoryStorage dialogs: [QBChatDialog]) {
    self.log.info()
    self.notifyOfNewMessage()
    self.delegate?.didUpdateDialogs(dialogs)
}

func chatService(_ chatService: QMChatService, didDeleteChatDialogWithIDFromMemoryStorage chatDialogID: String) {
    self.log.info()
    self.notifyOfNewMessage()
    self.delegate?.didDeleteDialogs()
}

func chatService(_ chatService: QMChatService, didAddMessageToMemoryStorage message: QBChatMessage, forDialogID dialogID: String) {
    self.log.info()
    self.notifyOfNewMessage()
    self.delegate?.didCreateMessages()
}

func chatService(_ chatService: QMChatService, didAddMessagesToMemoryStorage messages: [QBChatMessage], forDialogID dialogID: String) {
    self.log.info()
    self.notifyOfNewMessage()
    self.delegate?.didCreateMessages()
}

func chatService(_ chatService: QMChatService, didUpdate message: QBChatMessage, forDialogID dialogID: String) {
    self.log.info()
}

func chatService(_ chatService: QMChatService, didUpdate messages: [QBChatMessage], forDialogID dialogID: String) {
    self.log.info()
}

func chatService(_ chatService: QMChatService, didReceiveNotificationMessage message: QBChatMessage, createDialog dialog: QBChatDialog) {
    self.log.info()
}

func chatService(_ chatService: QMChatService, didLoadMessagesFromCache messages: [QBChatMessage], forDialogID dialogID: String) {
    self.log.info()
}

func chatService(_ chatService: QMChatService, didDeleteMessageFromMemoryStorage message: QBChatMessage, forDialogID dialogID: String) {
    self.log.info()
}

func chatService(_ chatService: QMChatService, didDeleteMessagesFromMemoryStorage messages: [QBChatMessage], forDialogID dialogID: String) {
    self.log.info()
}

func chatService(_ chatService: QMChatService, didLoadChatDialogsFromCache dialogs: [QBChatDialog], withUsers dialogsUsersIDs: Set<NSNumber>) {
    self.log.info()
}

// QBChatDelegate

func chatDidReceive(_ message: QBChatMessage) {
    self.log.info()

}

func chatRoomDidReceive(_ message: QBChatMessage, fromDialogID dialogID: String) {
    self.log.info(message.text)

}

编辑:删除了不相关的委托方法和对tableview的引用,因为它与在创建新对话框时没有调用委托方法的问题无关

1 个答案:

答案 0 :(得分:0)

每当发送/接收新消息时,您是否执行tableView.reloadData()。

确保更新用于返回tableView部分行数的数据结构。