iOS 预加载和杂七杂八

当产品把用户需求放在第一位的时候我就知道这事情不不简单,前些日子发现系统的一些可以用来实现预加载的方法;
如下:

// Display customization
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section API_AVAILABLE(ios(6.0));
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section API_AVAILABLE(ios(6.0));
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath API_AVAILABLE(ios(6.0));
- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section API_AVAILABLE(ios(6.0));
- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section API_AVAILABLE(ios(6.0));

如即将出现的行、头、尾,来实现当数据将要显示完,再次加载数据

//即将显示的行
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当 当前数据源的个数 和 数据源总数一致时 返回
    if (_num_rows >= _dataMutableArr.count)
    {
        return;
    }
    //当前的行数 小于 数据源个数的百分之八十 - 重新加载
    if (indexPath.row > _dataMutableArr.count * 0.8)
    {
        [_tableView.mj_footer beginRefreshing];
    }
}

获取当前Cell的位置系统方法

- (nullable NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;                         // returns nil if point is outside of any row in the table
- (nullable NSIndexPath *)indexPathForCell:(UITableViewCell *)cell;                      // returns nil if cell is not visible

获取当前屏幕顶部即将出现的Cell的位置,监听滑动方法

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
      //获取当前滑动到屏幕顶端的区数
      NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:scrollView.contentOffset];
      XNLog(@"滑动到第%ld区,第%ld行",indexPath.section,indexPath.row);
}

获取当前屏幕中部即将出现的Cell,同理

只需要改变
CGPointMake(0, scrollView.contentOffset.y + 当前tableView的一半)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前两次的分享分别介绍了 ASDK 对于渲染的优化以及 ASDK 中使用的另一种布局模型;这两个新机制的引入分别解决...
    Kevin追梦先生阅读 4,932评论 2 12
  • 本篇小结 这篇文章是 ASDK 系列中的最后一篇,文章会介绍 iOS 中几种预加载的方案,以及 ASDK 中是如何...
    那位小姐阅读 2,499评论 0 13
  • 用到的组件 1、通过CocoaPods安装 2、第三方类库安装 3、第三方服务 友盟社会化分享组件 友盟用户反馈 ...
    SunnyLeong阅读 14,651评论 1 180
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 7,552评论 16 22
  • 今天感恩节哎,感谢一直在我身边的亲朋好友。感恩相遇!感恩不离不弃。 中午开了第一次的党会,身份的转变要...
    迷月闪星情阅读 10,605评论 0 11