iOS 预加载和杂七杂八

2020-11-30  本文已影响0人  肖显圣

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

// 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的一半)
上一篇 下一篇

猜你喜欢

热点阅读