1. 集成 自带的 下拉属性控件 ---------HWHomeViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 集成刷新控件
[self setupRefresh];
}
/** 集成 下拉刷新 控件 */
- (void)setupRefresh
{
// 1.添加刷新控件
UIRefreshControl *control = [[UIRefreshControl alloc] init];
// 只有用户通过手动下拉刷新,才会触发UIControlEventValueChanged事件
[control addTarget:self action:@selector(refreshStateChange:) forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:control];
// 2.马上进入刷新状态(仅仅是显示刷新状态,并不会触发UIControlEventValueChanged事件)
[control beginRefreshing];
// 3.马上加载数据
[self refreshStateChange:control];
}
----------------------------------------------------------------------------------------------------------
/**
* UIRefreshControl进入刷新状态:加载最新的数据
*/
- (void)refreshStateChange:(UIRefreshControl *)control
{
// 1.请求管理者
AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
// 2.拼接请求参数
HWAccount *account = [HWAccountTool account];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"access_token"] = account.access_token;
// 取出最前面的微博(最新的微博,ID最大的微博)
HWStatus *firstStatus = [self.statuses firstObject];
if (firstStatus) {
// 若指定此参数,则返回ID比since_id大的微博(即比since_id时间晚的微博),默认为0
params[@"since_id"] = firstStatus.idstr;
}
// 3.发送请求
[mgr GET:@"https://api.weibo.com/2/statuses/friends_timeline.json" parameters:params success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
// 将 "微博字典"数组 转为 "微博模型"数组
NSArray *newStatuses = [HWStatus objectArrayWithKeyValuesArray:responseObject[@"statuses"]];
// 将最新的微博数据,添加到总数组的最前面
NSRange range = NSMakeRange(0, newStatuses.count);
NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:range];
[self.statuses insertObjects:newStatuses atIndexes:set];
// 刷新表格
[self.tableView reloadData];
// 结束刷新刷新
[control endRefreshing];
// 显示最新微博的数量
[self showNewStatusCount:newStatuses.count];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
HWLog(@"请求失败-%@", error);
// 结束刷新刷新
[control endRefreshing];
}];
}
1014-26-首页07-最新微博数量----出现一个微博数量的横幅
原文:http://www.cnblogs.com/nxz-diy/p/5267754.html