ios - 创建新对话框时没有调用委托(delegate)方法

标签 ios swift quickblox

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

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

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

我错过了什么?

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

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

在我的类(class)中,我将其设置为 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 可能的每个委托(delegate)方法;

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

}

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

最佳答案

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

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

关于ios - 创建新对话框时没有调用委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48545773/

相关文章:

ios - 在 uitableview 中使用多种单元格类型的问题

ios - 如何检测其他 SKSpriteNode 子节点的交叉节点

ios - 如何更改 UIGraphicsGetCurrentContext 的 fillColor?

ios - 为什么有时会出现 'The connection was lost' 错误?

ios - 为什么粒子系统只工作一次?

ios - 如何使用 QuickBox API 下载图像?

ios - 从 tableView 中删除一行的正确方法是什么?

swift - 扩展 ReactiveCocoa

ios - Quickblox 用户在线状态 IOS

android - 登录聊天 Quickblox 后获取聊天对话框