11

//下拉刷新数据

- (void)refreshStateChange:(UIRefreshControl *)refreshC

{

    /*

     URLhttps://api.weibo.com/2/statuses/friends_timeline.json

    

     请求参数:

     access_token   采用OAuth授权方式为必填参数,其他授权方式不需要此参数,OAuth授权后获得。

     count          单页返回的记录条数,最大不超过100,默认为20

     since_id   若指定此参数,则返回IDsince_id大的微博(即比since_id时间晚的微博),默认为0

     */

   

   

    WJAccount *act = [WJAccountToolreadAct];

    //请求管理者

    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManagermanager];

    //拼接请求参数

    NSMutableDictionary *params = [NSMutableDictionarydictionary];

    params[@"access_token"] = act.access_token;

    WJStatus *firstStatus = [self.statusesfirstObject];

    if (firstStatus) {

        params[@"since_id"] = firstStatus.idstr;

    }

    //发送请求

    [mgr GET: @"https://api.weibo.com/2/statuses/friends_timeline.json"parameters: params success:^(AFHTTPRequestOperation *operation, id responseObject) {

       

        //        NSArray *dictArray = responseObject[@"statuses"];

        //        for (NSDictionary *dict in dictArray) {

        //            WJStatus *status = [WJStatus objectWithKeyValues: dict];

        //            [self.statuses addObject: status];

        //        }

       

        //字典数组转成模型数组

        NSArray *newstatuses = [WJStatusobjectArrayWithKeyValuesArray: responseObject[@"statuses"]];

        //将最新的微博数据添加到总数组后面

        NSRange range = NSMakeRange(0, newstatuses.count);

        NSIndexSet *set = [NSIndexSetindexSetWithIndexesInRange: range];

        [self.statusesinsertObjects: newstatuses atIndexes: set];

       

        //刷新表格

        [self.tableViewreloadData];

       

        //结束刷新状态

        [refreshC endRefreshing];

       

        //显示得到最新微博的数量

        [selfshowNewStatusCount: newstatuses.count];

       

        //把最新未读数清空(显示在tabbar上的)

        self.tabBarItem.badgeValue = nil;

       

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

       

        [refreshC endRefreshing];

        WJLog(@"获取当前登录用户及其所关注用户的最新微博失败-%@", error);

    }];

}

posted on 2015-03-25 22:12  o无尘o  阅读(165)  评论(0编辑  收藏  举报