Question

I have hard coded a "loading" cell as the last cell of my table view, when this is generated I call some methods to load in new data from a web service, and when I get the response I save the data, dispatch a notification and call reloadData on my table view.

I want to do the same thing but for the first cell of my table.

My table is in function of time, so scrolling down shows you items from later dates, and the idea is to let the user scroll higher and load earlier items.

I can't seem to successfully set an initial offset to hide this loading cell, because if it is shown then it will begin loading earlier data of course. I am aware of scrollToRowAtIndexPath:atScrollPosition:animated: but I can't find an appropriate place to call it (with index path: 1:0 row 1 section 0).

As I mentioned before I need to set this visible section before any cells are called to be created.

Has anyone tried this kind of cell at the start of a table view ?

How can I set an initial visible section of my table view before the first cells are even called to be loaded ?

Should I be doing something more fancy here ? Like having a tableviewHeader and when that is shown I insert a row at index path 0:0 which is the loader, and remove it after I reloadTable ?

Was it helpful?

Solution

I used contentInset, not offset in viewDidLoad.

[self.tableView setContentInset:UIEdgeInsetsMake(-50,0,0,0)];

When row at index path [0,0] is generated I reset the inset, this happens in tableView:cellForRoWAtIndexPath:

[self.tableView setContentInset:UIEdgeInsetsMake(0,0,0,0)];

Each time before messaging reloadData on the table view I put that inset back on:

- (void)reload{
    [self.tableView setContentInset:UIEdgeInsetsMake(-50,0,0,0)];
    [self.tableView reloadData];
}

This means my loading cell is only ever sitting on screen when it's viewed, when the new data comes in and table reloads I put the offset back.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top