-(void)loadData{
//开始网络请求
AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
//默认请求类型
manager.responseSerializer=[AFHTTPResponseSerializer serializer];
//GET方法
[manager GET:@"http://123.126.40.109:7003/asmr/videos/A1100101.shtml" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
//解析数据 if为字典我们就用字典方法
NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:responseObject options:1 error:nil];
//字典里面包含数组 将字典里面的数组标题复制给arr
NSArray *arr=dict[@"result"];
//打印
NSLog(@"%@",dict[@"result"]);
//用for in 遍历字典与数组
for (NSDictionary *dic in arr) {
//初始化model
SModel *model=[[SModel alloc]init];
//将解析的标题给定义的属性
[self.dataSourceimagv addObject:dic[@"imageUrl"]];
[self.dataSourcezlable addObject:dic[@"fileDescribe"]];
[self.dataSourceshipin addObject:dic[@"fileUrl"]];
//将for in 的字典dic 给model;
[model setValuesForKeysWithDictionary:dic];
//将model给数据源便于调用
[self.dataSource addObject:model];
}
NSLog(@"%@",self.dataSourceimagv);
[self performSelectorOnMainThread:@selector(reloadTable) withObject:nil waitUntilDone:NO];
NSLog(@"网络请求 成功");
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"请求数据错误");
}];
}
-(void)reloadTable{
//刷新网格数据
[yyCollectionView reloadData];
}
coco:
pod ‘AFNetworking’
pod ‘MJRefresh’
pod ‘SDWebImage’
pod ‘SVProgressHUD’
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//如果集合视图是重新排序的或具有丢弃占位符,则返回“是”。
//网格视图占位
[yyCollectionView deselectItemAtIndexPath:indexPath animated:NO];
//初始化
NextViewController *next =[[NextViewController alloc] init];
//将视频数据源赋值给字符串
self.stringg=self.dataSourceshipin[indexPath.row];
//将视频值给播放便于下个页面播放
next.mp4Url=self.stringg;
// next.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:next animated:YES];
}
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
NS_ASSUME_NONNULL_BEGIN
@interface NextViewController : MPMoviePlayerViewController
//播放数值
@property(nonatomic,strong)NSString *mp4Url;
@end
NS_ASSUME_NONNULL_END
#import "NextViewController.h"
@interface NextViewController ()
@end
@implementation NextViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 获取播放url
self.moviePlayer.contentURL=[NSURL URLWithString:self.mp4Url];
//开始播放
[self.moviePlayer play];
[self createBackBtn];
}
//返回页面
-(void)createBackBtn{
UIButton *btn =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 50)];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(pushBack) forControlEvents:UIControlEventTouchUpInside];
}
-(void)pushBack{
[self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end