ios NSNotificationCenter接受通知不能操作UI執行緒
[self.tableViewreloadRowsAtIndexPaths:@[[NSIndexPathindexPathForRow: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.ChatRoomIdisEqualToString:message.targetId
model.unreadMsg = @([[RCIMClientsharedRCIMClient] getUnreadCount:ConversationType_GROUPtargetId:message.targetId]);
dispatch_async(dispatch_get_main_queue(), ^{
NSArray *visiableCells = self.tableView.visibleCells;
HomeListCell *cell = [self.tableViewcellForRowAtIndexPath:[NSIndexPath
if ([visiableCells containsObject:cell]) {
[self.tableViewreloadRowsAtIndexPaths:@[[NSIndexPathindexPathForRow:i inSection:0]]withRowAnimation:UITableViewRowAnimationAutomatic];
}
});
break;
}
}
}
}