oOOMIAO 2013-05-02 02:37 采纳率: 10%
浏览 2172
已采纳

表视图滚动到底部的获取

iPhone中有表试图。想实现两个功能:

1.用户将表滚动到底部时。
2.用户拉下了tableview时。

例如:

If(UserScrollThe tableViewToTop)
{
 perform action: 1
}

If(UserScrollThe tableViewToDown)
{
 perform action: 2
}

如何获取用户进行了这两个动作?

  • 写回答

1条回答

  • ReyZhang 移动开发领域新星创作者 2013-05-07 01:35
    关注

    UITableView is a subclass of UIScrollView, and UITableViewDelegate conforms to UIScrollViewDelegate. So the delegate you attach to the table view will get events such as scrollViewDidScroll:, and you can call methods such as contentOffset on the table view to find the scroll position.

    in the tableview delegate do something like this

    - (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
        CGPoint offset = aScrollView.contentOffset;
        CGRect bounds = aScrollView.bounds;
        CGSize size = aScrollView.contentSize;
        UIEdgeInsets inset = aScrollView.contentInset;
        float y = offset.y + bounds.size.height - inset.bottom;
        float h = size.height;
        // NSLog(@"offset: %f", offset.y);   
        // NSLog(@"content.height: %f", size.height);   
        // NSLog(@"bounds.height: %f", bounds.size.height);   
        // NSLog(@"inset.top: %f", inset.top);   
        // NSLog(@"inset.bottom: %f", inset.bottom);   
        // NSLog(@"pos: %f of %f", y, h);
    
        float reload_distance = 10;
        if(y > h + reload_distance) {
            NSLog(@"load more rows");
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog