今天遇到了一個很奇怪的問題,整合融雲聊天,,擷取群組未讀訊息數量的時候,我寫了一個通知,再通知中更新tableview Cell中的訊息數量,但是訊息數量改變的很慢,而且有時候不更新 我是更新某一個cell
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];在測試的時候發現,cell的drawRect方法不執行,如果是直接reloadData ,就沒問題,,
在log中發現了一句 This application is modifying the autolayout engine from a background thread after the engine was a ,下面是我的通知方法,這樣在main線程中重新整理就沒什麼問題了,
- (void)receiveMessage:(NSNotification *)notification
{
RCMessage *message = [[notification object] objectForKey:@"message"];
if (message) {
for (NSInteger i=0; i<self.customerArray.count; i++) {
CustomerModel *model = self.customerArray[i];
if ([model.ChatRoomId isEqualToString:message.targetId]) {
model.unreadMsg = @([[RCIMClient sharedRCIMClient] getUnreadCount:ConversationType_GROUP targetId:message.targetId]);
dispatch_async(dispatch_get_main_queue(), ^{
NSArray *visiableCells = self.tableView.visibleCells;
HomeListCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
if ([visiableCells containsObject:cell]) {
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
});
break;
}
}
}
}