美文网首页
刷新加载(OC_UI)

刷新加载(OC_UI)

作者: Miss_差不多 | 来源:发表于2017-08-19 09:19 被阅读7次

ViewController.m

#import "ViewController.h"
#import "MJRefresh.h"
#import "EAHTTPClient.h"
#import "Song.h"

@interface ViewController ()
<
UITableViewDataSource,
UITableViewDelegate
>
@property (nonatomic,retain) NSMutableArray *songArray;
@property (nonatomic,retain) UITableView *tableView;
@property (nonatomic,assign) BOOL refresh;
@property (nonatomic,assign) NSInteger page;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.songArray = [NSMutableArray array];
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:tableView];
    self.tableView = tableView;
    tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        NSLog(@"luck");
        self.refresh = YES;
        self.page = 1;
        [self loadDataWithPage:self.page];
        //结束刷新
        [tableView.mj_header endRefreshing];
    }];
    //自动刷新
    [tableView.mj_header beginRefreshing];
    tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
         self.refresh = NO;
        NSLog(@"one");
        self.page++;
        [self loadDataWithPage:self.page];
        [tableView.mj_footer endRefreshing];
    }];
    [tableView.mj_footer beginRefreshing];
    
    
}


- (void)loadDataWithPage:(NSInteger)pageName{
    NSString *URLSreing = @"http://172.18.26.201/get.php";
    NSDictionary * parameters = @{@"page":[NSString stringWithFormat:@"%ld",pageName]};
    [EAHTTPClient GET:URLSreing parameters:parameters success:^(id reponseObject) {
        if (self.refresh) {
            [self.songArray removeAllObjects];
            [self.tableView.mj_header endRefreshing];
        }else{
            [self.tableView.mj_footer endRefreshing];
        }
        
        
        for (NSDictionary *songDic in reponseObject ) {
            Song *song = [[Song alloc] init];
            [song setValuesForKeysWithDictionary:songDic];
            [self.songArray addObject:song];
        }
        [self.tableView reloadData];
        
        } failure:^(NSError *error) {
            
        
    }];


}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.songArray.count;

}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    Song *song = self.songArray[indexPath.row];
    static NSString *cellId = @"cell";
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellId];
    if (nil == cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
    }
    cell.textLabel.text = song.name;
    cell.detailTextLabel.text = song.singerName;
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

Song.h

@property (nonatomic,copy)NSString *name;
@property (nonatomic,copy)NSString *number;
@property (nonatomic,copy)NSString *pic;
@property (nonatomic,copy)NSString *singerName;
@property (nonatomic,copy)NSString *url;

Song.m

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{


}

在这个工程里主要用了第三方框架MJRefresh和EAHTTPClient来实现刷新加载的效果,第一个在github上就可以找到,第二个想要的童鞋可以私信我哦。
这个工程主要就是实现了刷新加载的效果,没有什么深层的知识 大家自行体会吧!!!!

相关文章

  • 刷新加载(OC_UI)

    ViewController.m Song.h Song.m 在这个工程里主要用了第三方框架MJRefresh和E...

  • APICloud刷新和加载

    刷新: 加载:

  • html 页面的优化处理(ajax)

    同步加载(刷新):每次刷新的是整个页面的数据 异步加载(刷新):每次刷新的是整个页面的部分数据 由于之前做公司内部...

  • RecyclerView刷新和上拉加载

    说到上拉加载,总是离不开刷新。没有刷新,哪有后面的上拉加载。所以“刷新”和“上拉加载”是有时间的先后顺序,有关联性...

  • 刷新加载

    刷新设置: 上拉加载更多 设置: tableview上拉加载更多页面跳动问题 问题研究:将cell的高度固定 然后...

  • 刷新加载

    依赖://Smart刷新/加载 implementation 'com.scwang.smartrefresh:S...

  • 日更的决心

    文/阿呆鳥.Lcanus 刷新 刷新 网络 太慢 加载 加载 网络 断线 同步 同步 失败 失败 再来 再来 阿弥...

  • 列表适配器

    ------上拉下拉刷新加载------****SmartRefreshLayout 智能下拉刷新框架~20190...

  • vant ui中 PullRefresh and List

    需求:展示(用户)账户的明细,需要懒加载和下拉刷新效果(List实现懒加载,PullRefresh实现下拉刷新) ...

  • ionic4 入门 (五) 上拉加载 下拉刷新

    ionic4 (入门) 上拉加载 下拉刷新 继续 ionic 开发首页 上拉加载 下拉刷新 html 部分代码 下...

网友评论

      本文标题:刷新加载(OC_UI)

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