UITableView insertRowsAtIndexPaths:WithRowAnimation without freeze UI

别等时光非礼了梦想. 提交于 2019-12-04 14:42:18

问题


I try to understand what is the best practice to use when I work with UITableView with large number of row to insert when the table is visible.

This is my behavior:

I have one UITableView and one Thread that try to insert a data into this table. I think that make a [UITableView reloadData] is a poor solution for the performance aspect, and I know that UIKit operation are be carried on main thread, for this reason when the datasource update is completed I tried to send a NSNotification to make a UITableView update operation (beginUpdate - insertRowAtIndex - endUpdate) on the main thread, but this technique freeze the user interface. I have to work with 1000+ number of rows.

Someone has already solved this problem ? Is it a possible solution the use of GDC async and sync? If yes, how? Thanks in advance.


回答1:


Do you try like this:

dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView beginUpdates];
        [self.tableDatalist insertObject:obj atIndex:index];

        [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]]
                              withRowAnimation:UITableViewRowAnimationRight];
        [self.tableView endUpdates];
    });


来源:https://stackoverflow.com/questions/22482323/uitableview-insertrowsatindexpathswithrowanimation-without-freeze-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!