model 层
? ? ? .h 文件 ?
- (instancetype)initModel: (NSDictionary *)dic;
+ (instancetype)HuiDiao: (NSDictionary *)dic;
.m ?
- (instancetype)initModel: (NSDictionary *)dic
{
if (self = [super init])
{
[self setValuesForKeysWithDictionary:dic];
}
return self;
}
+ (instancetype)HuiDiao: (NSDictionary *)dic
{
return? [[self alloc]initModel:dic];
}
表格中自定义cell 利用第三方 展示图片"SDWebImage"
#import "UIImageView+WebCache.h"
[cell.imageVi sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"3dcbc92925711f3d!400x400_big.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
}];
block 传值 ?业务处理层. h
typedef void (^shipinBlock)(NSMutableArray *arr);
//声明 block 属性
@property (nonatomic,strong) shipinBlock shujublock;
+ (instancetype)DL;
//用于回传数据的方法
//声明block 的方法
//-(void)shujuchuanzhi:(shujuBlock)shuju;
- (void)GETJSON:(NSString *)urlStr shujuchuanzhi:(shipinBlock)shuju;
//业务处理层. m
+ (instancetype)DL
{
if (shipin == nil)
{
shipin = [[shipinDataBase alloc]init];
}
return shipin;
}
-(void)GETJSON:(NSString *)yaowenUrlStr shujuchuanzhi:(shipinBlock)shuju
{
_dic = [[NSMutableDictionary alloc]init];
_allarr = [NSMutableArray array];
//NSURL *url = [NSURL URLWithString:yaowenUrlStr];
//创建管理器
AFHTTPSessionManager *manage = [AFHTTPSessionManager manager];
manage.responseSerializer = [[AFHTTPResponseSerializer alloc]init];
NSString *str = [shipinUrlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[manage GET:str parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id? _Nullable responseObject) {
NSLog(@"视频数据获取成功");
_dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
//获取字典里的数据
NSMutableArray *arrdata = [_dic objectForKey:@"videoList"];
//遍历字典
//
for (NSDictionary *dic4 in arrdata) {
//初始化数据模型
shipinModel *yaowen = [shipinModel yy_modelWithDictionary:dic4];;
[_allarr addObject:yaowen];
//NSLog(@"++++++++%@",yaowen.mp4_url);
shuju(_allarr);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"获取失败");
}];
}