5

The problem is the UI appears and then gets updated : giving a flickering affect.

I want the UI to be updated only once when user enters app, thus i've put reload in ViewDidLoad.. Here is the code .. Any help how can remove this flickering ... Some code example would help.

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


    }];
});
user3576169
  • 81
  • 2
  • 7
  • what is your issue, please elaborate your question. – iPatel Apr 26 '14 at 14:24
  • The problem is the UI appears and then gets updated : giving a flickering affect. – user3576169 Apr 26 '14 at 14:27
  • I require the cells to be updated without the full TableView flickering .. I refered this http://stackoverflow.com/questions/11631104/uitableview-reloaddata-how-to-stop-flicker but didnt help – user3576169 Apr 26 '14 at 14:35

4 Answers4

3

Why don't you simply call reloadSections method instead of [self.tableView reloadData];

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
Zoeb S
  • 695
  • 1
  • 7
  • 21
2

Refer cellForRowAtIndexPath delegate method. You might be doing some operation that might cause a flick. In my case, I was setting an image of an image view with animation. So whenever I reload the table, it was flickering due to that animation.

I removed that animation and worked for me..

NSPratik
  • 4,714
  • 7
  • 51
  • 81
1

Hope the below lines can help you in delaying and flickering issues

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

 });
Pandey_Laxman
  • 3,889
  • 2
  • 21
  • 39
  • actually tableview only reload visible cells by default – Pandey_Laxman Apr 26 '14 at 14:41
  • 2
    **I understand i need to do this.** '[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];' **But that gives an error :** 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. – user3576169 Apr 26 '14 at 14:41
  • This would stop a background thread related crash, but not a refresh flicker – Wain Apr 26 '14 at 14:41
1

Your download is asynchronous, so it won't complete before the view is shown. So, whatever you have in CollectionQueryResult will get displayed.

You could either:

  1. Clear CollectionQueryResult so the table isn't populated till you get an update
  2. Compare CollectionQueryResult and objects, then update only the visible cells where the data has changed (before setting CollectionQueryResult)

Note that for option 2 you will also need to compare the count of CollectionQueryResult and objects and then insert / delete rows from the table view as appropriate. The whole point of option 2 is to not call reloadData, so you need to do a lot more work...

You can also avoid calling reloadRowsAtIndexPaths if you get the visible cells and update them directly (which avoids any animation from happening). See cellForRowAtIndexPath:.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • **I understand i need to do this.** `[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];` **But that gives an error :** 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. – user3576169 Apr 26 '14 at 14:44
  • How can deal with this error , coz i am not passing the no. of rows manually – user3576169 Apr 26 '14 at 14:46
  • The number of rows is returned in the delegate method. If you update `CollectionQueryResult` then you need to call `reloadRowsAtIndexPaths`, `insertRowsAtIndexPaths` and `deleteRowsAtIndexPaths` based on the difference between the old and new contents of `CollectionQueryResult` – Wain Apr 26 '14 at 14:53