【简单常用】下拉刷新


导入完整的MJRefresh文件夹

头文件声明

#import"MJRefresh.h"

 

@property(nonatomic,retain)UITableView*tableView;

全局tableView,方便使用

 

//

//  MYViewController.m

 

 

#import"MYViewController.h"

@interface MYViewController()

@end

@implementation MYViewController

 

 

//下拉刷新

-(void)headerRereshing

{

           添加数据,想办法

 

    // 2.2秒后刷新表格UI

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(2.0* NSEC_PER_SEC)), dispatch_get_main_queue(),^{

        // 刷新表格

        [self.tableView reloadData];

       

        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态

        [self.tableView headerEndRefreshing];

    });

}

 

//下拉加载

-(void)footerRereshing

{

    // 2.2秒后刷新表格UI

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(2.0* NSEC_PER_SEC)), dispatch_get_main_queue(),^{

        // 刷新表格

        [self.tableView reloadData];

 

        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态

        [self.tableView footerEndRefreshing];

    });

}

 

 

 

- (void)viewDidLoad

{

    [super viewDidLoad];

 

    _array=[[NSArray alloc]initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",nil];

 

 

    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 400) style:UITableViewStyleGrouped];

    _tableView.delegate=self;

    _tableView.dataSource=self;

    [self.view addSubview:_tableView];

   

   

//集成刷新控件

    [self setupRefresh];

   

    // Do anyadditional setup after loading the view.

}

 

//刷新提示内容

- (void)setupRefresh

{

   

    [_tableViewaddHeaderWithTarget:selfaction:@selector(headerRereshing)];

#warning自动刷新(一进入程序就下拉刷新)

    [_tableViewheaderBeginRefreshing];

 

    [_tableViewaddFooterWithTarget:selfaction:@selector(footerRereshing)];

   

    // 设置文字(也可以不设置,默认的文字在MJRefreshConst中修改)

    _tableView.headerPullToRefreshText = @"下拉可以刷新";

    _tableView.headerReleaseToRefreshText = @"松开马上刷新";

    _tableView.headerRefreshingText = @“数据加载中;

   

    _tableView.footerPullToRefreshText = @"上拉加载更多数据";

    _tableView.footerReleaseToRefreshText = @"松开加载更多数据";

    _tableView.footerRefreshingText = @“数据加载中;

   

}

 

 

 

 

 

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}

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

{

    return 11;

}

 

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

{

    static NSString*CellIndenttifier=@"Cell";

    UITableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:CellIndenttifier];

    if(cell==nil) {

        cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndenttifier];

    }

   

    cell.textLabel.text=[_array objectAtIndex:[indexPath row]];

   

   

    returncell;

}

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose ofany resources that can be recreated.

}

 

/*

#pragmamark - Navigation

 

//In a storyboard-based application, you will often want to do a littlepreparation before navigation

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{

    // Get the new view controller using [seguedestinationViewController].

    // Pass the selected object to the new viewcontroller.

}

*/

 

@end

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值