3

I have a Uitableview with loading mode like that, When user scroll to item 5 it'll auto load 10 item and add in the top of label. My problem is when add like that, current cell move down 10 item, it's bad look.

Can we add cell at top UITableView but current cell not move up or down until user scroll.

QViet
  • 297
  • 5
  • 25
  • Does this answer your question? [Keep uitableview static when inserting rows at the top](https://stackoverflow.com/questions/4279730/keep-uitableview-static-when-inserting-rows-at-the-top) – Rivera Dec 06 '19 at 12:27

2 Answers2

1

What you could do is insert your rows, then use scrollToRowAtIndexPath:atScrollPosition:animated: method to scroll to the row you would like to display. More info here.

gcamp
  • 14,622
  • 4
  • 54
  • 85
Chance Hudson
  • 2,849
  • 1
  • 19
  • 22
  • Thanks Gcamp but in your way table will look not normal, it's scroll down when add item and scroll up when call >scrollToRowAtIndexPath:atScrollPosition:animated: – QViet Jun 01 '11 at 08:06
  • 1
    You could just set animated to NO, then it would just go to it, but that may still look unnatural. – Chance Hudson Jun 13 '11 at 22:29
0

Just posted an answer with code snippets here

Keep uitableview static when inserting rows at the top

Basically:

  • Save the scroll offset where you would have called beginUpdate:.
  • In place of calls to InsertCell you add the cell's height to the saved offset.
  • Where you would have called endUpdate:, call reloadData, then scroll by the saved offset with NO animation.
Community
  • 1
  • 1
Walt Sellers
  • 3,806
  • 30
  • 35