zoukankan      html  css  js  c++  java
  • 新浪微博客户端(18)-集成下拉刷新控件UIRefreshControl

    HomeViewController.m

    - (void)setupPullToRefreshView {
    
        UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
        [refreshControl addTarget:self action:@selector(refreshNewData:) forControlEvents:UIControlEventValueChanged];
        [self.tableView addSubview:refreshControl];
    
    }
    
    
    #pragma mark - UIRefreshContorl 监听方法
    - (void)refreshNewData:(UIRefreshControl *)control {
    
        AFHTTPSessionManager *requestManager = [AFHTTPSessionManager manager];
        
        NSString *urlString = @"https://api.weibo.com/2/statuses/friends_timeline.json";
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        params[@"access_token"] = [DJAccountTool account].access_token;
        DJStatus *status = [self.statuses firstObject];
        if (status) {
            params[@"since_id"] = status.idstr;
        }
        [requestManager GET:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
            NSArray *newStatuses = [DJStatus mj_objectArrayWithKeyValuesArray:responseObject[@"statuses"]];
            // 将刷新获取到的新数据添加到总数组的头部
            NSRange range = NSMakeRange(0, newStatuses.count);
            NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndexesInRange:range];
            [self.statuses insertObjects:newStatuses atIndexes:indexSet];
            // 刷新TableView
            [self.tableView reloadData];
            // 隐藏RefreshControl
            [control endRefreshing];
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [control endRefreshing]; // 当数据获取失败时结束刷新操作
        }];
        
    
    }

    最终效果:

  • 相关阅读:
    遍历MapControl中的图层方法总结
    ArcEngine加载SDE图层
    C#+ArcEngine 新建点元素
    sql日期查询问题
    MSSQL 将截断字符串或二进制数据
    gridview的Rowcommand命令中获取行索引的方法总结
    利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用
    ArcGIS Server开发示例诠释
    将ASP.NET MVC 2.0 部署在IIS6
    [OpenCV+C#]开发环境的搭建
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6024707.html
Copyright © 2011-2022 走看看