Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>'UITableView' is same as 'UIScrollView' in 'scrollViewDidScroll' method.</p> <p>So, its easy to emulate infinite scrolling.</p> <ol> <li><p>double the array so that head and tail are joined together to emulate circular table</p></li> <li><p>use my following code to make user switch between 1st part of doubled table and 2nd part of doubled table when they tend to reach the start or the end of the table.</p></li> </ol> <p>:</p> <pre><code>/* To emulate infinite scrolling... The table data was doubled to join the head and tail: (suppose table had 1,2,3,4) 1 2 3 4|1 2 3 4 (actual data doubled) --------------- 1 2 3 4 5 6 7 8 (visualising joined table in eight parts) When the user scrolls backwards to 1/8th of the joined table, user is actually at the 1/4th of actual data, so we scroll instantly (we take user) to the 5/8th of the joined table where the cells are exactly the same. Similarly, when user scrolls to 6/8th of the table, we will scroll back to 2/8th where the cells are same. (I'm using 6/8th when 7/8th sound more logical because 6/8th is good for small tables.) In simple words, when user reaches 1/4th of the first half of table, we scroll to 1/4th of the second half, when he reaches 2/4th of the second half of table, we scroll to the 2/4 of first half. This is done simply by subtracting OR adding half the length of the new/joined table. */ -(void)scrollViewDidScroll:(UIScrollView *)scrollView_ { CGFloat currentOffsetX = scrollView_.contentOffset.x; CGFloat currentOffSetY = scrollView_.contentOffset.y; CGFloat contentHeight = scrollView_.contentSize.height; if (currentOffSetY &lt; (contentHeight / 8.0)) { scrollView_.contentOffset = CGPointMake(currentOffsetX,(currentOffSetY + (contentHeight/2))); } if (currentOffSetY &gt; ((contentHeight * 6)/ 8.0)) { scrollView_.contentOffset = CGPointMake(currentOffsetX,(currentOffSetY - (contentHeight/2))); } } </code></pre> <p>P.S. - I've used this code on one of my apps called NT Time Table (Lite). If you want the preview, you can check out the app: <a href="https://itunes.apple.com/au/app/nt-time-table-lite/id528213278?mt=8" rel="nofollow">https://itunes.apple.com/au/app/nt-time-table-lite/id528213278?mt=8</a></p> <p>If your table can sometimes be too short, at the beginning of the above method you can add a if logic to exit the method when data count is say for example less than 9.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload