[self.tableview reloadData]; causes flickering
Asked Answered
H

4

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
        }


    }];
});
Hluchy answered 26/4, 2014 at 14:22 Comment(3)
what is your issue, please elaborate your question.Trimly
The problem is the UI appears and then gets updated : giving a flickering affect.Hluchy
I require the cells to be updated without the full TableView flickering .. I refered this #11631604 but didnt helpHluchy
M
3

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

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
Mansfield answered 6/6, 2014 at 15:17 Comment(1)
still the image on tableview is flickering.Decision
R
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..

Regnant answered 19/5, 2016 at 10:32 Comment(0)
L
1

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

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

 });
Lumpkin answered 26/4, 2014 at 14:35 Comment(3)
actually tableview only reload visible cells by defaultLumpkin
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.Hluchy
This would stop a background thread related crash, but not a refresh flickerAb
A
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:.

Ab answered 26/4, 2014 at 14:40 Comment(3)
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.Hluchy
How can deal with this error , coz i am not passing the no. of rows manuallyHluchy
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 CollectionQueryResultAb

© 2022 - 2024 — McMap. All rights reserved.