iOS Nsnotificationcenter accept notifications cannot manipulate UI threads

Source: Internet
Author: User
Today I met a very strange problem, integrated cloud chat, to get the number of unread group, I wrote a notice to update the number of messages in the TableView cell, but the number of messages changed very slowly, and sometimes not update I was updating a cell

[Self.tableview Reloadrowsatindexpaths:@[[nsindexpath indexpathforrow:i insection:0]] WithRowAnimation: Uitableviewrowanimationautomatic]; At the time of testing found that the cell DrawRect method does not execute, if it is direct reloaddata, there is no problem,

Found a sentence in the log this application is modifying the AutoLayout engine from a background thread after the engine was a, below is my pass Know the method so that it's OK to refresh in the main thread,


-(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


}

}

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.