There is a tableview. It is necessary during the approximation of a cell from the top (let indexPath.row = 1) run a query to add data to the table. Accordingly, the user must stay where he was and flipped through the table. This happens, for example, in the VK application, while viewing a dialogue. You scroll through and see how the slider itself goes down below.

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ((indexPath.section == 0) && (indexPath.row == 1)) { [self loadMore]; } } 

This is where I launch the update method. Next, it starts the call to the server. By answering which I do the following:

 CGFloat initialOffset = self.tableView.contentOffset.y; [self.tableView reloadData]; [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:items.count inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO]; CGPoint afterContentOffset = self.tableView.contentOffset; CGPoint newContentOffset = CGPointMake(afterContentOffset.x, afterContentOffset.y + initialOffset); self.tableView.contentOffset = newContentOffset; 

Where items is the new items that came to be displayed in the table.

And it works almost as it should, but loading stops the user. This does not happen smoothly.

Does someone know how to do the same as dialogs in VC work?

Those. Need precisely smoothness work.

  • I understand that the download is in the main stream and therefore pidtormozhue, read about GCD. - Orest Mykha
  • No, the download is in the block, which is launched by the response from the server. The slowdown is due to the fact that you have to run scrollToIndexPath and change the contentOffset in this way. For the user, this pours into stopping his browsing. - user2568603

1 answer 1

If you are using the iOS 10+ version, then there is a wonderful thing that preloads cells in advance - prefetching. Read more here .

Also, if using prefetching is impossible for some reason, then fill the cell asynchronously, for example, using dispatch_async. This approach can also be seen in Vkontakte, when the image in the tape is loaded later.