美文网首页
ios 刷新自定义数据

ios 刷新自定义数据

作者: 你又脸红了i | 来源:发表于2018-11-13 13:51 被阅读0次

#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

相关文章

网友评论

      本文标题:ios 刷新自定义数据

      本文链接:https://www.haomeiwen.com/subject/pszkfqtx.html