; 导致闪烁

问题是用户界面出现,然后得到更新:闪烁的影响。

当用户input应用程序时,我只想更新用户界面一次,因此我已经把重新加载到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 } }]; }); 

为什么不直接调用reloadSections方法而不是[self.tableView reloadData];

 [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone]; 

请参阅cellForRowAtIndexPath委托方法。 您可能正在做一些可能会导致轻弹的操作。 就我而言,我正在用animation设置图像视图的图像。 所以,每当我重新加载表,由于该animation闪烁。

我删除了该animation,并为我工作..

希望下面的行可以帮助你延迟和闪烁的问题

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

您的下载是asynchronous的,所以在显示视图之前它不会完成。 所以,无论你在CollectionQueryResult有什么,都会显示出来。

你可以:

  1. 清除CollectionQueryResult以便在更新之前不会填充表
  2. 比较CollectionQueryResultobjects ,然后仅更新数据已更改的可见单元格(在设置CollectionQueryResult之前)

请注意,对于选项2,您还需要比较CollectionQueryResultobjects的计数,然后根据需要插入/删除表视图中的行。 选项2的全部是不要调用reloadData ,所以你需要做更多的工作…

你也可以避免调用reloadRowsAtIndexPaths如果你得到可见的单元格并直接更新它们(避免发生任何animation)。 请参阅cellForRowAtIndexPath: