1

Is there any way in objective C to know table reload is over? I have to do some code after table reload.

  • 3
    Nope. In general you don't need that information unless your architecture is wrong. – Sulthan Feb 07 '17 at 06:43
  • Pls describe flow of work. – dahiya_boy Feb 07 '17 at 06:44
  • What do you exactly want? – User511 Feb 07 '17 at 06:44
  • http://stackoverflow.com/questions/4163579/how-to-detect-the-end-of-loading-of-uitableview Check @malhal’s answer. – kb920 Feb 07 '17 at 06:47
  • Does the table view know? Table views load as many data as they need to display its content. If the table view is partially shown (i. e. because it is too big), the rest of the data is loaded, when the user scrolls down. Or earlier. Or whatever. There is no guarantee. What kind of work is that you have to do after reloading? – Amin Negm-Awad Feb 07 '17 at 06:55
  • What you excatly trying to do ? Maybe there is better ways. I used table views so many times and i never needed it before. Maybe do you have lots of contents to show ? Maybe you need something like lazy loadings ? – Yucel Bayram Feb 07 '17 at 07:25

3 Answers3

0
Try this codes:

[self.tableView reloadData];

# below I use myArr array to loop data for tableView

dispatch_async(dispatch_get_main_queue(), ^{
     NSIndexPath* indexPath = [NSIndexPath indexPathForRow: ([self.tableView numberOfRowsInSection:([self.tableView numberOfSections]-1)]-1) inSection:([self.tableView numberOfSections]-1)];
    enter code here

if(myArr == (indexPath+1)){
 #execute your logic here
}
});
0

The TableView reload happens during the next layout pass, which normally happens when you return control to the run loop.

So one way to run something after the table view reloads is to force the table view to perform layout immediately:

[self.yourTableView reloadData];
[self.yourTableView layoutIfNeeded];
NSIndexPath* indexPath = [NSIndexPath indexPathForRow: ([self.yourTableView numberOfRowsInSection:([self.yourTableView numberOfSections]-1)]-1) inSection: ([self.yourTableView numberOfSections]-1)];
// Your Action goes here

Another approach: Perform schedule your after-layout code to run later using dispatch_async:

[self.yourTableView reloadData];

dispatch_async(dispatch_get_main_queue(), ^{
     NSIndexPath* indexPath = [NSIndexPath indexPathForRow: ([self.yourTableView numberOfRowsInSection:([self.yourTableView numberOfSections]-1)]-1) inSection:([self.yourTableView numberOfSections]-1)];

// Check Index Path if it's last then perform your action
});

OR

Use UITableView willDisplayCell method

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
        //end of loading
        //Do whatever the Action required. Like Stop indicator, etc...
    }
}
Niraj
  • 1,939
  • 20
  • 29
0

You could use CATransaction

[CATransaction begin];
[CATransaction setCompletionBlock:^{
    NSLog(@"Done Loading");
}];

[self.tableView reloadData];

[CATransaction commit];
RyanZ
  • 1
  • 1
  • 2