网络请求

-(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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值