如何获得UITableView的可见部分? [英] How to get a UITableView's visible sections?

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

问题描述

UITableView 提供方法 indexPathsForVisibleRows visibleCells ,但是我怎样才能得到可见的部分?

UITableView provides the methods indexPathsForVisibleRows and visibleCells, but how can I get the visible sections?

推荐答案

我已经得到了解决方案。

I have got the solution.

第一步,每个部分将显示由创建的UIView - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)部分,它将被存储到数组中。

First step, each section will show a UIView that created by - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section, that will be stored into array.

当滚动TableView时,我想要释放不可见的部分视图,所以我需要知道哪个部分是否可见,跟随功能代码将检测为此目的,如果视图可见,则释放它。

When the TableView is scrolled , I want free the invisible section view, so I need know which section is visible or not, follow function code will detect for this purpose, if the view is visible then free it.

-(BOOL)isVisibleRect:(CGRect)rect containerView:(UIScrollView*)containerView
{
    CGPoint point = containerView.contentOffset;
    CGFloat zy = point.y ;

    CGFloat  py =  rect.origin.y + rect.size.height;
    if (py - zy <0) {
            return FALSE;
    }
    CGRect  screenRect = containerView.frame;

    CGFloat by = screenRect.size.height + zy ;
    if (rect.origin.y > by) {
            return FALSE;
    }
    return TRUE;
}

rect 是部分的框架 UIView ; containerView UITableView

(rect is the frame of the section UIView; containerView is the UITableView)

通过这种方式,我可以获得 UITableView 的可见部分,但我希望SDK可以提供API为了这个目的直接。

In this way, I can get visible sections of the UITableView, but I hope the SDK can provide API for this purpose directly.

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

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