我有一个对话框列表,当新消息发布到现有对话框时,该列表会按预期更新。
当有人在新对话框(即不在 TableView 中的对话框)中向我发送新消息时,不会有任何更新。尽管我输入并记录了每个 QBChatDelegate
和 QBChatServiceDelegate
方法,但似乎没有调用委托(delegate)方法。
我已将其设置为当我转到另一个 View 并返回 TableView 时,它会手动检索对话框并重新加载 TableView 。不过我需要它自动更新。
我错过了什么?
编辑:当前登录用户以外的其他人创建新对话框时应触发哪个委托(delegate)方法?
编辑:一些用于更多上下文的代码......
在我的类(class)中,我将其设置为 QBChatDelegate
和 QBChatServiceDelegate
;
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
}
})
})
然后,我调用 QBChatDelegate
和 QBChatServiceDelegate
可能的每个委托(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/