新闻视频部分

1.创建M V C文件
2.在M文件中创建继承NSObject的文件为VIdeoModel
3.在VIdeoModel.h中写属性

@property(nonatomic,copy)NSString *replyCount;//跟贴

@property(nonatomic,copy)NSString *cover;//图片

@property(nonatomic,copy)NSString *title;//标题

@property(nonatomic,copy)NSString *playCount;//播放数

@property(nonatomic,copy)NSString *mp4_url;//视频链接

@property(nonatomic,copy)NSString *length;//时长

4.VIdeoModel.m中写入

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

5.在V文件中创建继承UITableViewCell文件记得点击✅xib为VideoCell
6.在VideoCell.h中写属性

@property (weak, nonatomic) IBOutlet UIImageView *coverImgV;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *lengthLabel;
@property (weak, nonatomic) IBOutlet UILabel *playLabel;
@property (weak, nonatomic) IBOutlet UILabel *replyLabel;

-(void)loadDataFromModel:(VideoModel *)model;

7.在VideoCell.m中

-(void)loadDataFromModel:(VideoModel *)model{
    if(model){
        
        [self.coverImgV sd_setImageWithURL:[NSURL URLWithString:model.cover]];
        self.titleLabel.text = model.title;
        self.lengthLabel.text = [NSString stringWithFormat:@"时长 %@",model.length];
        self.playLabel.text = [NSString stringWithFormat:@"播放 %@",model.playCount];
        self.replyLabel.text = [NSString stringWithFormat:@"评论 %@",model.replyCount];
        
    }
    
    
}

8.xib拖图
在这里插入图片描述
9.在C文件中创建继承ViewController的文件为VideoViewController
10.在VideoViewController.m文件中

#import "VideoCell.h"
#import "VideoModel.h"
#import "VideoDetailViewController.h"
@interface VideoViewController ()<UITableViewDelegate , UITableViewDataSource>
@property(nonatomic , strong)UITableView *tableView;
@property(nonatomic , strong)NSMutableArray *dataSource;
@end

@implementation VideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.dataSource = [[NSMutableArray alloc]init];
    
    [self.view addSubview:self.tableView];
    
    [self loadData];
    [self addFooterRefresh];
    [self addHeaderRefresh];
    
}
-(void)loadData{
    // 显示加载栏
    [SVProgressHUD showWithStatus:@"加载中..."];
    // 创建网络请求
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    // 设置默认请求类型,(NSData
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:VIDEO_PATH parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 解析数据
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:1 error:nil];
        NSArray *resultArray = dict[@"V9LG4B3A0"];
        for (NSDictionary *dic in resultArray) {
            VideoModel *model = [VideoModel new];
            [model setValuesForKeysWithDictionary:dic];
            [self.dataSource addObject:model];
        }
        // 刷新界面
        [self performSelectorOnMainThread:@selector(reloadTable) withObject:nil waitUntilDone:NO];
        // 消失
        [SVProgressHUD dismiss];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        // 消失
        [SVProgressHUD dismiss];
        NSLog(@"数据请求失败");
    }];
    
}
// 刷新
-(void)reloadTable{
    
    [self.tableView reloadData];
    
}


-(UITableView *)tableView{
    
    if(!_tableView){
        
        _tableView = [[UITableView alloc]initWithFrame:self.view.frame];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
    }
    
    [_tableView registerNib:[UINib nibWithNibName:@"VideoCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    
    return _tableView;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    VideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [cell loadDataFromModel:self.dataSource[indexPath.row]];
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}
// 点击单元格灰色消失
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    VideoDetailViewController *detail = [VideoDetailViewController new];
    VideoModel *model = self.dataSource[indexPath.row];
    detail.mp4Url = model.mp4_url;
    detail.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:detail animated:YES];
}
- (void)addHeaderRefresh{
    /*
     系统原生下拉刷新
     UIRefreshControl * refresh = [[UIRefreshControl alloc]init];
     [refresh addTarget:self action:@selector(refreshDown) forControlEvents:UIControlEventValueChanged];
     [refresh setAttributedTitle:[[NSAttributedString alloc]initWithString:@"刷新..."]];
     [self.tableView addSubview:refresh];
     //    [refresh endRefreshing];//停止刷新
     */
    /*
     普通状态刷新
     MJRefreshNormalHeader * header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
     NSLog(@"MJRefresh触发");
     }];
     self.tableView.header = header;
     */
    MJRefreshGifHeader * header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        //1、重置页数
        // self.page = 1;
        //2、清空数据源
        [self.dataSource removeAllObjects];
        //3、重新发生网络请求
        [self loadData];
    }];
    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:@"敌军还有30秒到达战场" forState:MJRefreshStateRefreshing];
    self.tableView.mj_header = header;
}
- (void)refreshDown{
    NSLog(@"下拉刷新触发");
}
- (void)addFooterRefresh{
    //上拉刷新
    MJRefreshAutoGifFooter * footer = [MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
        //1、页数增加
        //self.page++;
        //2、重新请求数据
        [self loadData];
    }];
    NSArray * imageArr = @[[UIImage imageNamed:@"loading_teemo_1"],[UIImage imageNamed:@"loading_teemo_2"]];
    [footer setImages:imageArr forState:MJRefreshStateRefreshing];
    self.tableView.mj_footer = footer;
}

@end

11.创建文件VideoDetailViewController继承 MPMoviePlayerViewController
12.导入数据库

#import <MediaPlayer/MediaPlayer.h>

13.VideoDetailViewController.h中

@interface VideoDetailViewController : MPMoviePlayerViewController
@property(nonatomic , strong)NSString *mp4Url;
@end

14.在VideoDetailViewController.m中

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.moviePlayer.contentURL = [NSURL URLWithString:self.mp4Url];
    [self.moviePlayer play];
    
    // 创建返回按钮方法
    [self creataBackBtn];
    
}
-(void)creataBackBtn{
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(pushBack) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)pushBack{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBar.hidden = YES;
    
}
-(void)viewWillDisappear:(BOOL)animated{
    
    self.navigationController.navigationBar.hidden = YES;
    
}


@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值