IOS上、下拉表视图刷新加载数据

在项目开发过程中为了更好的体验经常会用到下拉刷新更新数据。当前比较火的EGOTableViewPullRefresh只实现了下拉功能,而没有上拉的功能。这里介绍一个同时集成下拉刷新和上拉加载更多的类库EGOTableViewPullRefresh

下载地址:https://github.com/MPK-Github/tableViewPullRefresh

用法很简单,如下:

  • 添加 QuartzCore.framework 到你的工程中。
  • 将 EGOTableViewPullRefresh 拖到你的工程目录下。
  • 查看 PullTableView.h 文件可用的属性。
  • 添加一个PullTableView 到你代码中,实现PullTableViewDelegate委托方法
控制器.m 文件实现如下:

//

//  ViewController.m

//  tableViewPullRefresh

//

//  Created by imac on 15/9/13.

//  Copyright (c) 2015 mapengkun. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    // 1.创建表视图

    _pullTableView = [[PullTableView alloc] initWithFrame:CGRectMake(0, 64, 320, 568- 64) style:UITableViewStyleGrouped];

    // 2.设置相关属性,可以点击PullTableView文件,查看相关属性

    _pullTableView.pullArrowImage = [UIImage imageNamed:@"blackArrow"];

    _pullTableView.pullBackgroundColor = [UIColor yellowColor];

    _pullTableView.pullTextColor = [UIColor blackColor];

    

   // 3.实现数据源协议和代理,(记得在.h文件里实现)

    _pullTableView.dataSource = self;

    _pullTableView.delegate = self;

    // 4.添加到主视图中

    [self.view addSubview:_pullTableView];

}


#pragma mark -Refresh and LoadMoredata Method


// 刷新表视图的方法

- (void)refreshTable

{

    _pullTableView.pullLastRefreshDate = [NSDate date];

    

    _pullTableView.pullTableIsRefreshing = NO;

}

// 加载更多数据的方法

- (void)loadMoreDataToTable

{

    _pullTableView.pullTableIsLoadingMore = NO;

}







#pragma mark - UTTableViewDataSource


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 5;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return 8;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *cellIdentify = @"Cell";

    

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];

    

    if (!cell) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify];

    }

    

    cell.textLabel.text = [NSString stringWithFormat:@"Row %ld",indexPath.row];

    

    return cell;

}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    return [NSString stringWithFormat:@"Section %ld begins here!",section];

}


- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

{

    return [NSString stringWithFormat:@"Section %ld ends here!",section];


}




- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return 20;

}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    return 20;

}



#pragma mark - PullTableDelegate


- (void)pullTableViewDidTriggerRefresh:(PullTableView *)pullTableView

{

    [self performSelector:@selector(refreshTable) withObject:nil afterDelay:3.0];

}


- (void)pullTableViewDidTriggerLoadMore:(PullTableView *)pullTableView

{

    [self performSelector:@selector(loadMoreDataToTable) withObject:nil afterDelay:3.0];

}






- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


希望对你们有所帮助,欢迎到博客进行转载



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值