SVPullToRefresh下拉上拉刷新的详细使用

2017-04-26  本文已影响0人  全栈的猫南北

具体代码:

- (void)refreshAndReloadData {

添加下拉刷新方法

__weak typeof(self)weakself = self;

[_doctorCLV addPullToRefreshWithActionHandler:^{

_start1 =0;

[weakself requestData:doctorListURL start:[NSString stringWithFormat:@"%ld",_start1]];

}];

//程序自动调用下拉刷新方法

[_doctorCLV triggerPullToRefresh];

//设置自定义标题

[_doctorCLV.pullToRefreshView setTitle:@"加载更多" forState:(SVPullToRefreshStateAll)];

NSDate *nowDate = [NSDate date];

NSDateFormatter *dataFormatter = [[NSDateFormatter alloc]init];

[dataFormatter setDateFormat:@"YYYY/MM/dd:hh:mm:ss"];

NSString *nowString = [dataFormatter stringFromDate:nowDate];

//设置子标题

[_doctorCLV.pullToRefreshView setSubtitle:nowString forState:(SVPullToRefreshStateAll)];

//设置箭头颜色

_doctorCLV.pullToRefreshView.arrowColor = [UIColor cyanColor];

上拉加载

[_doctorCLV addInfiniteScrollingWithActionHandler:^{

_start1 +=10;

[weakself requestData:doctorListURL start:[NSString stringWithFormat:@"%ld",_start1]];

}];

[_doctorCLV triggerInfiniteScrolling];

}

网络加载

- (void)requestData:(NSString *)url start:(NSString*)start{

NSDictionary *dic = @{@"page":@(start.integerValue),@"rows":@10,@"departmentid":@(_keshi.integerValue)};

[hRequestTools  requestWithURLString:url parameters:dic type:2 success:^(id responseObject) {

NSLog(@"%@",responseObject);

NSDictionary *dict = (NSDictionary *)responseObject;

NSLog(@"dict is %@",dict);

NSArray *arr =dict[@"list"];

for (NSDictionary *dic in arr)

{

DoctorModel *model = [[DoctorModel alloc]init];

[model setValuesForKeysWithDictionary:dic];

[self.dataArr1 addObject:model];

}

_doctorCLV.dataSource = self;

_doctorCLV.delegate = self;

[self.doctorCLV  reloadData];

} failure:^(NSError *error) {

[HTools showTextOnlyHud:[NSString stringWithFormat:@"%@",error] delay:2.0];

}];

[_doctorCLV.pullToRefreshView stopAnimating];

[_doctorCLV.infiniteScrollingView stopAnimating];

}

上一篇下一篇

猜你喜欢

热点阅读