我想创建一个UITableView的日期,应该不是很令人兴奋,我知道。它从当前日期开始,但用户应该能够向下滚动(未来)以上(过去)尽可能远。这会导致可能的无限数量的行。那么创建这个有什么办法呢?永恒滚动UITableView
返回NSIntegerMax
作为行数已经崩溃的应用程序,但即使它不会,这仍然不能考虑能够滚动。我当然可以开始,但最终会有一个最大值。
任何想法如何做或假这?我可以更新/重新加载表格,而不需要用户注意,所以我从来没有碰到边界?
SOLUTION:
我去@安德的建议,并与细胞的固定量做了一桌。但当用户滚动到固定单元格的边缘附近时,我不用重新加载它,而是在滚动停止时重新加载表格。为了适应用户在不停止的情况下滚动很长的距离,我只是将行数增加到了1000,并将ROW_CENTER常量设置为500.这是用于更新行的方法。
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSArray *visible = [self.tableView indexPathsForVisibleRows];
NSIndexPath *upper = [visible objectAtIndex:0];
NSIndexPath *lower = [visible lastObject];
// adjust the table to compensate for the up- or downward scrolling
NSInteger upperDiff = ROW_CENTER - upper.row;
NSInteger lowerDiff = lower.row - ROW_CENTER;
// the greater difference marks the direction we need to compensate
NSInteger magnitude = (lowerDiff > upperDiff) ? lowerDiff : -upperDiff;
self.offset += magnitude;
CGFloat height = [self tableView:self.tableView heightForRowAtIndexPath:lower];
CGPoint current = self.tableView.contentOffset;
current.y -= magnitude * height;
[self.tableView setContentOffset:current animated:NO];
NSIndexPath *selection = [self.tableView indexPathForSelectedRow];
[self.tableView reloadData];
if (selection)
{
// reselect a prior selected cell after the reload.
selection = [NSIndexPath indexPathForRow:selection.row - magnitude inSection:selection.section];
[self.tableView selectRowAtIndexPath:selection animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
魔符当用户滚动表中的边缘没有停止,但与表视图bounces
属性禁用,这只是感觉就像一个小故障,但完全可以接受的。一如既往,感谢StackOverflow!
请在下面我的答案中试用一下代码。它使用一个简单的逻辑。 –