下拉刷新,上拉删除表格

popo继承pod ‘MJRefresh’
v.h

@property (nonatomic , assign)int page;

v.m

#import "ViewController.h"
#import <MJRefresh.h>
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>{
    UITableView *tab;
}
@property(nonatomic,strong)NSMutableArray * dataSource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    tab=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    tab.delegate=self;
    tab.dataSource=self;
    [self.view addSubview:tab];
    _dataSource = [NSMutableArray arrayWithObjects:@"张三",@"李四",@"王五",@"张三",@"李四",@"王五", nil];
    self.page = 1;
    [self addheaderRefresh];
    [self addFooterRefresh];
  
    
    
    
}


//下拉
-(void)addheaderRefresh{
    MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        //重新发送网络请求
        [self loadData];

        
    }];
    tab.mj_header=header;
    // 设置文字
    [header setTitle:@"完事" forState:MJRefreshStateIdle];
    [header setTitle:@"(ಥ _ ಥ)" forState:MJRefreshStatePulling];
    [header setTitle:@"?" forState:MJRefreshStateRefreshing];
    
    // 设置字体
    header.stateLabel.font = [UIFont systemFontOfSize:15];
    header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14];
    
    // 设置颜色
    header.stateLabel.textColor = [UIColor redColor];
    header.lastUpdatedTimeLabel.textColor = [UIColor blueColor];
//            // 隐藏时间
//            header.lastUpdatedTimeLabel.hidden = YES;
//            // 隐藏状态
//            header.stateLabel.hidden = YES;
    
}
//下拉添加
-(void)loadData{
    
    //添加内容
    [self.dataSource addObject:@"盖伦"];
    //刷新表格
    [self->tab reloadData];
    //请求时间
    sleep(2);
    //下拉结束
    [self->tab.mj_header endRefreshing];
    
    
}
//上拉加载
-(void)addFooterRefresh{
    MJRefreshAutoGifFooter *footer=[MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
        // 重新发送网络请求
        [self removeData];
    }];
        tab.mj_footer = footer;
}
//上拉加载
-(void)removeData{
    //删除最后一个
    [_dataSource removeLastObject];
    //刷新表格
    [tab reloadData];
    //加载时间
    sleep(2);
    //关闭加载
    [tab.mj_footer endRefreshing];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell=[tab dequeueReusableCellWithIdentifier:@"cc"];
    if(!cell){
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"11"];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%@",_dataSource[indexPath.row]];
//    cell.textLabel.text=arr[indexPath.row];
    return cell;
}

@end

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值