[IOS]SVPullToRefresh的使用

来源:互联网 发布:unity3d 获取脚本组件 编辑:程序博客网 时间:2024/06/06 17:37

[IOS]SVPullToRefresh的使用

SVPullToRefresh使用比较简单,只要一行语句即可实现下拉并刷新。比EGOPullToRefresh更简单。

GitHub地址:https://github.com/samvermette/svpulltorefresh

Demo地址:http://download.csdn.net/detail/u012881779/8477137

#import "SVViewController.h"#import "SVPullToRefresh.h"@interface SVViewController ()<UITableViewDelegate , UITableViewDataSource>@property (strong, nonatomic) IBOutlet UITableView *tableView;@end@implementation SVViewController- (void)viewDidLoad {    [super viewDidLoad];    _tableView.delegate = self;    _tableView.dataSource = self;    //下拉刷新    __weak SVViewController * weakVC = self;    [weakVC.tableView addPullToRefreshWithActionHandler:^{        [weakVC refreshAction];        [weakVC performSelector:@selector(stopRefreshAnimation) withObject:nil afterDelay:3];    }];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];}//下拉刷新-(void)refreshAction{    [_tableView reloadData];}//停止下拉刷新-(void)stopRefreshAnimation{    [self.tableView.pullToRefreshView stopAnimating];}#pragma mark UITableViewDataSource- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return 20;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        static NSString *CellIdentifier = @"Cell";    UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];    if (cell==nil) {        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];    }        [cell.textLabel setText:[NSString stringWithFormat:@"%d",indexPath.row]];    return cell;}#pragma mark UITableViewDelegate- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    return 50;}@end

示图:




0 0
原创粉丝点击