ios 刷新自定义数据

#import "ViewController.h"

#import "MJRefresh.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

{

    NSMutableArray*_dataSource;

    UITableView *tbv;

}

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];


    tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];

    tbv.delegate=self;

    tbv.dataSource = self;

    [self.view addSubview:tbv];

    _dataSource = [NSMutableArray arrayWithObjects:@"张三",@"李四",@"王五",@"张三",@"李四",@"王五", nil];

    self.page=1;

    [self addHeaderRefresh];

    [self addFooterRefresh];

}

-(void)addHeaderRefresh{


    MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{


        // (3)重新发送网络请求

        [selfloadData];


    }];

    tbv.mj_header= header;


}

-(void)loadData{

    [_dataSource addObject:@"盖伦"];


    [tbv reloadData];


    sleep(2);

    [tbv.mj_header endRefreshing];

}

// 上拉加载

-(void)addFooterRefresh{


    MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingBlock:^{

        // 页面增加


        // 重新发送网络请求

        [selfremoveData];


    }];

    tbv.mj_footer= footer;

}

-(void)removeData{

    [_dataSource removeLastObject];

    [tbv reloadData];


    sleep(2);

    [tbv.mj_footer endRefreshing];

}

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

    return _dataSource.count;

}

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    if (!cell) {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];

    }

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

    returncell;

}

@end

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容