Uitableview autoupadate when scrolling up

I want to update the Uitableview when it scrolls up. As in the facebook application, when we scroll through the uitableview, it will show “upadating” and insert new rows at the top of the table. I want to give the same effect in my application. Is it possible to design it using the uifyview default methods or do we need to configure it. If anyone has an idea about this, please respond.

+3
source share
3 answers

You can use insertRowsAtIndexPaths:to insert new rows at the front of the table. For instance,

 NSIndexPath *indexPathForRow_0_0 = [NSIndexPath indexPathForRow:0 inSection:0];
 NSIndexPath *indexPathForRow_0_1 = [NSIndexPath indexPathForRow:1 inSection:0];
 [yourTableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:indexPathForRow_0_0, indexPathForRow_0_1, nil] withRowAnimation:UITableViewRowAnimationTop];

The above code inserts two rows at index 0 and 1 into section 0.

. dataSource delegate, . , numberOfRowsInSection. , , numberOfRowsInSection yourPreviousNumberOfRows + 2, .

+2

, :

:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y == 0)
        NSLog(@"At the top");
}

: scrollViewDidScrollToTop UITableView?

:

scrollViewDidScrollToTop: 

: http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/UIScrollView_pg/ScrollingViewContent/ScrollingViewContent.html

: , , .

insertRowsAtIndexPaths:withRowAnimation:

: http://www.mlsite.net/blog/?p=466

[tableView reloadData], , . deleteRowsAtIndexPaths: withRowAnimation: , , .

+7

Another way:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
            [self fetchMoreMessages];
    }
}
+5
source

Source: https://habr.com/ru/post/1789163/