0

I am trying to create a UItableView with infinite scrolling mode , I mean when tableview reaches at its end for example row 100 it must show row 0 to row 100 again. Is there any possible way to do so ? If yes can you help me out ?

iOS.Lover
  • 5,923
  • 21
  • 90
  • 162

1 Answers1

1

I believe this could work theoretically but have never tried it myself.

Also, this only works if you scroll down infinitely, not up.

To do this, in cellForRowAtIndexPath, you can use a switch statement where you are 'switching' indexPath.row % 99 (replace 99 with however many cells you have in total minus 1), and each case is 0, 1, 2, etc.

switch (indexPath.row % (dataSource.count() - 1) {
    case 0:

    case 1:

         ...
}

Hope this helps!

This answer also has a good solution.

Community
  • 1
  • 1
Daniel
  • 3,188
  • 14
  • 34
  • I mean what should I write in case 0 case1 ? – iOS.Lover Jul 04 '16 at 08:49
  • @Mc.Lover, that's where the properties of the respective cells go. If you have something simpler, like setting the title of the cell from data in an array, then you can simply say, 'cell.textLabel.text = data[data.count() % indexPath.row]' – Daniel Jul 04 '16 at 14:50