UITableView分页 [英] UITableView Pagination

查看:98
本文介绍了UITableView分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用已自定义 UITableView 单元格。我想一次只显示一个单元格 - 下一个单元格应该部分显示。在ScrollView中,您可以将 isPagingEnabled 设置为YES。

My app has custom UITableView cells. I want to show only one cell at a time - next cell should show partially. In ScrollView you can set isPagingEnabled to YES.

但我怎么能在 UITableView 上面做?

谢谢

推荐答案

请注意 UITableView 继承自 UIScrollView ,因此您可以在表视图本身上将 pagingEnabled 设置为 YES

Note that UITableView inherits from UIScrollView, so you can set pagingEnabledto YES on the table view itself.

当然,这只有在所有单元格和表格视图本身具有相同高度时才有效。

Of course, this will only work if all cells and the table view itself are of the same height.

如果你想在滚动后总是在表格视图的顶部开始一个单元格,你可以使用 UIScrollViewDelegate 并实现类似的东西。

If you want to always have a cell start at the top of the table view after scrolling, you could use a UIScrollViewDelegate and implement something like this.

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
                     withVelocity:(CGPoint)velocity
              targetContentOffset:(inout CGPoint *)targetContentOffset
{
  UITableView *tv = (UITableView*)scrollView;
  NSIndexPath *indexPathOfTopRowAfterScrolling = [tv indexPathForRowAtPoint:
                                                       *targetContentOffset
                                                 ];
  CGRect rectForTopRowAfterScrolling = [tv rectForRowAtIndexPath:
                                             indexPathOfTopRowAfterScrolling
                                       ];
  targetContentOffset->y=rectForTopRowAfterScrolling.origin.y;
}

这使您可以调整滚动操作将结束的内容偏移量。

This lets you adjust at which content offset a scroll action will end.

这篇关于UITableView分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆