iOS—知乎日报第二周总结

请求历史数据

在manage里面封装新的请求方法,在后面添加获取的时间
在这里插入图片描述
这是获取的天数,每次请求后将天数向前推一天
在这里插入图片描述

 NSString *json = [NSString stringWithFormat: @"https://news-at.zhihu.com/api/4/news/before/%@",beforeDay];

每次刷新的时候都会调用此方法

刷新

将cell的section设置成为可变类型
停止拖动的时候计算屏幕差,来判断是否调用新的请求
同时启用加载控件
创建一个空cell用来布局加载控件

 BlankTableViewCell* mainCell = [self.mainTableView dequeueReusableCellWithIdentifier:@"blankCell" forIndexPath:indexPath];

        mainCell.selectionStyle = UITableViewCellSelectionStyleNone;
        _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
        _activityIndicatorView.backgroundColor = [UIColor whiteColor];
        [_activityIndicatorView startAnimating];
        
        [mainCell addSubview: _activityIndicatorView];
        _activityIndicatorView.frame = CGRectMake(Width / 2 - 8, 25, 15, 15);
        return mainCell;

每次请求后reload tableview
使用以下方法计算屏幕差
写在- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

   if (scrollView.tag == 1) {
        CGFloat height = scrollView.frame.size.height;
        CGFloat contentOffsetY = scrollView.contentOffset.y;
        CGFloat bottomOffset = scrollView.contentSize.height - contentOffsetY; //计算屏幕差
        if (bottomOffset <= height * 1.2) {



            [_delegate getBefore];
        }

这里是v与c使用协议传值,用来接收请求
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
注意的是这里也是要注意线程问题的

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值