当前位置: 首页 > 工具软件 > Progress HUD > 使用案例 >

OC:MJ-HUD

赏高格
2023-12-01

#import “SVProgressHUD.h”
#import “MJRefresh.h”

  • (void)loadNewData{
    //显示加载栏
    [SVProgressHUD showWithStatus:@“加载中…”];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@“text/html”];
    [manager GET:@"" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {

      } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
          NSLog(@"%@",responseObject);
          NSArray *arr = responseObject[@"result"];
          NSDictionary *dict = [arr objectAtIndex:0];
          // 添加数据
          for (NSDictionary *dic in dict.allValues) {
              Model *model = [Model new];
              [model setValuesForKeysWithDictionary:dic];
              [self.array addObject:model];
          }
          [self.ojtable reloadData];
          //取消刷新控件
          [self.ojtable.mj_header endRefreshing];
          [self.ojtable.mj_footer endRefreshing];
          //去掉加载栏
          [SVProgressHUD dismiss];
      } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
          NSLog(@"%@",error);
          //提示用户
          //取消刷新控件
          [self.ojtable.mj_header endRefreshing];
          [self.ojtable.mj_footer endRefreshing];
          //去掉加载栏
          [SVProgressHUD dismiss];
      }];
    

}

/ 添加头部刷新
-(void)addheaderrefresh{
MJRefreshGifHeader *header=[MJRefreshGifHeader headerWithRefreshingBlock:^{

    //初始化页数
    //清空数据源
    [self.array removeAllObjects];
    //重新发送网络请求
    [self loadNewData];
}];
NSArray * imageArr = @[[UIImage imageNamed:@"common_loading_anne_0"],[UIImage imageNamed:@"common_loading_anne_1"]];
//添加正在刷新中的状态
[header setImages:imageArr forState:MJRefreshStateRefreshing];
//闲置状态
[header setImages:@[[UIImage imageNamed:@"common_loading_anne_0"]] forState:MJRefreshStateIdle];
//文字
[header setTitle:@"马上完成....." forState:MJRefreshStateRefreshing];
self.ojtable.mj_header=header;

}
//上拉加载
-(void)addfootrefresh{
MJRefreshAutoGifFooter *footer=[MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
//重新请求数据
[self loadNewData];
}];
NSArray * imageArr = @[[UIImage imageNamed:@“loading_teemo_1”],[UIImage imageNamed:@“loading_teemo_2”]];
[footer setImages:imageArr forState:MJRefreshStateRefreshing];
self.ojtable.mj_footer=footer;
}

 类似资料: