[self.tableview reloadData]; 导致闪烁

use*_*169 5 tableview reloaddata ios

问题是UI出现然后得到更新:产生闪烁的影响.

我希望UI只在用户输入app时更新一次,因此我在ViewDidLoad中重新加载..这是代码..任何帮助如何消除这种闪烁...一些代码示例会有所帮助.

- (void)viewDidLoad { 

[super viewDidLoad];

self.myTableView.dataSource = self;
self.myTableView.delegate = self;

PFQuery * getCollectionInfo = [PFQuery queryWithClassName:@"Collection"];   // make query

[getCollectionInfo orderByDescending:@"updatedAt"];
[getCollectionInfo setCachePolicy:kPFCachePolicyCacheThenNetwork];

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
    [getCollectionInfo findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            CollectionQueryResult = (NSMutableArray *)objects;
                [self.tableView reloadData];


            // whenevr get result
        }
        else{
            //no errors
        }


    }];
});
Run Code Online (Sandbox Code Playgroud)

Pan*_*man 1

希望以下几行可以帮助您解决延迟和闪烁问题

dispatch_async(dispatch_get_main_queue()
                   , ^{
 [self.tableView reloadData];

 });
Run Code Online (Sandbox Code Playgroud)

  • **我知道我需要这样做。** '[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];' **但这会产生错误:** 'NSInternalInconsistencyException',原因:'无效更新:第 0 节中的行数无效。 (2认同)