Make the first row of the UITableView hidden until the user scrolls the iPhone

For Facebook and several other iPhone apps, I saw what looks like a UITableView with the top row out of sight while other rows are rendered. Then, when the user scrolls, the first line becomes visible. Typically, the top line is the "load more ..." element.

Is there a trick when the second row looks like the first in the table?

+3
source share
2 answers

There are several ways to do this. The easiest way is to set tableView contentOffset to CGPointMake (0, rowHeight). This will automatically scroll the first line out of sight. Do this in your viewWilLAppear: method.

+6
source

You can use the scrollToRowAtIndexPath: atScrollPosition: animated method: without animation to scroll the second line when loading your view and before it appears:

- (void)viewWillAppear:(BOOL)animated 
{
    [super viewWillAppear:animated];

    // This is just an example... make sure you have at least
    // three items in your table :)
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];

    [self.tableView scrollToRowAtIndexPath:indexPath 
                          atScrollPosition:UITableViewScrollPositionTop 
                                  animated:NO];
}
+2
source

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


All Articles