UITableView scrollViewDidScroll विधि में UIScrollView के समान है।
तो, अनंत स्क्रॉलिंग अनुकरण करना आसान है।
डबल सरणी ताकि सिर और पूंछ एक साथ शामिल हो गए हैं गोल मेज का अनुकरण करने
दोगुनी मेज और दोगुनी तालिका के 2 भाग जब वे करते हैं के 1 भाग के बीच उपयोगकर्ता स्विच करने के लिए मेरे निम्नलिखित कोड का उपयोग टेबल की शुरुआत या अंत तक पहुंचने के लिए।
:
/* 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.)
Thus, 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 < (contentHeight/8.0)) {
scrollView_.contentOffset = CGPointMake(currentOffsetX,(currentOffSetY + (contentHeight/2)));
}
if (currentOffSetY > ((contentHeight * 6)/ 8.0)) {
scrollView_.contentOffset = CGPointMake(currentOffsetX,(currentOffSetY - (contentHeight/2)));
}
}
पी.एस. - मैंने एनटी टाइम टेबल (लाइट) नामक मेरे ऐप्स में से एक पर इस कोड का उपयोग किया है। यदि आप पूर्वावलोकन चाहते हैं, तो आप ऐप देख सकते हैं: https://itunes.apple.com/au/app/nt-time-table-lite/id528213278?mt=8
यदि आपकी तालिका कभी-कभी बहुत कम हो सकती है, तो उपर्युक्त विधि की शुरुआत में आप डेटा गिनती के लिए विधि से बाहर निकलने के लिए तर्क जोड़ सकते हैं 9 से कम उदाहरण।
स्रोत
2012-07-12 05:21:57
मुझे लगता है कि यह यह है। यहां करने के लिए कुछ भी सुरुचिपूर्ण नहीं है; कम से कम पंक्तियां सभी वर्चुअल हैं ताकि आप उन्हें फ्लाई पर बना सकें। – drw
@drw: कृपया इस लिंक का अनुसरण करें: [लिंक] (http://stackoverflow.com/questions/5675535/how-to-implement-cyclic-scrolling-on-tableview) –
नीचे मेरा उत्तर देखें। यह कोड मिला है। मैं उस कोड का उपयोग लंबे समय से कर रहा हूं। यह काम करता हैं। –