model传值

界面
导入分段控制器的第三方
要点 注册网格 网格内设置cell 内容
model写一个方法
model.h里写数组 名字要对应 key
cell 里调用model的数据

网格界面 写数据源把model的数据传进去

#import "oneViewController.h"
#import "SCNavTabBarController.h"
#import "quanbuViewController.h"
#import "jingxuanViewController.h"
@interface oneViewController ()

@end

@implementation oneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.barTintColor=[UIColor whiteColor];
    
    UIView*vi=[[UIView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
    
    UIButton*btn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0,40, 40)];
    [btn setImage:[UIImage imageNamed:@"屏幕快照 2018-11-20 下午7.09.59.png"] forState:UIControlStateNormal];
    [vi addSubview:btn];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:vi];
    [self you];
    [self sear];
    [self fenduan];
    
}
-(void)you{
    UIView*vi=[[UIView alloc] initWithFrame:CGRectMake(100, 10, 100, 50)];
//    vi.backgroundColor=[UIColor redColor];
    UIButton*btn=[[UIButton alloc] initWithFrame:CGRectMake(10, 0, 40, 40)];
    [btn setImage:[UIImage imageNamed:@"屏幕快照 2018-11-20 下午7.09.59.png"] forState:UIControlStateNormal];
    [vi addSubview:btn];
    UIButton*btn2=[[UIButton alloc] initWithFrame:CGRectMake(70, 0, 40, 40)];
    [btn2 setImage:[UIImage imageNamed:@"屏幕快照 2018-11-20 下午7.09.59.png"] forState:UIControlStateNormal];
    [vi addSubview:btn2];
    
    
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:vi];
}
-(void)sear{
    UISearchBar*sear=[[UISearchBar alloc] initWithFrame:CGRectMake(10, 10, 10, 10)];
    sear.placeholder=@"回答";
    self.navigationItem.titleView=sear;
}
-(void)fenduan{
    jingxuanViewController*jingxuan=[jingxuanViewController new];
    jingxuan.title=@"精选";
    jingxuan.view.backgroundColor=[UIColor redColor];
    
    
    quanbuViewController*quanbu=[quanbuViewController new];
    quanbu.title=@"全部";
    quanbu.view.backgroundColor=[UIColor whiteColor];
    
    SCNavTabBarController*scnav=[SCNavTabBarController new];
    scnav.subViewControllers=@[quanbu,jingxuan];
    [scnav addParentController:self];
}

分段控制器里的内容

#import "quanbuViewController.h"
#import "eeCollectionViewCell.h"
#import "shipinViewController.h"
#import "Model.h"
@interface quanbuViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
{
    UICollectionView*collew;
}
@property(nonatomic,strong)NSMutableArray*datasoure;

@end

@implementation quanbuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.datasoure=[NSMutableArray new];
    
    self.datasoure=[Model getDataSource];
    UICollectionViewFlowLayout*flow=[[UICollectionViewFlowLayout alloc] init];
    flow.itemSize=CGSizeMake(207, 320);
    flow.minimumLineSpacing=0;
    flow.minimumInteritemSpacing=0;
    
    collew=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flow];
    collew.delegate=self;
    collew.dataSource=self;
    
    [collew registerClass:[eeCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    collew.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:collew];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 6;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    eeCollectionViewCell*cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    
    [cell setValueForCell:self.datasoure[indexPath.row]];

    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
 shipinViewController*shi=[[shipinViewController alloc]init];
 [self.navigationController pushViewController:shi animated:YES];
    
}

cell.h

@property(nonatomic,strong)UIImageView*img;
@property(nonatomic,strong)UILabel*zlabel;
@property(nonatomic,strong)UILabel*flabel;

-(void)setValueForCell:(Model *)mod;

cell.m


#import "eeCollectionViewCell.h"

@implementation eeCollectionViewCell
-(void)setValueForCell:(Model *)mod{
    if (mod) {
        self.img.image=[UIImage imageNamed:mod.arrimg];
        self.zlabel.text=mod.arrzlabel;
        self.flabel.text=mod.arrflabel;
    }
}
-(instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        [self addSubview:self.img];
        [self addSubview:self.zlabel];
        [self addSubview:self.flabel];
    }
    return self;
}

-(UIImageView *)img{
    if (!_img) {
        _img=[[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 180, 220)];
    }
    return _img;
}
-(UILabel *)zlabel{
    if (!_zlabel) {
        _zlabel=[[UILabel alloc] initWithFrame:CGRectMake(5, 220, 180, 50)];
    }
    return _zlabel;
}
-(UILabel *)flabel{
    if (!_flabel) {
        _flabel=[[UILabel alloc] initWithFrame:CGRectMake(10, 260, 100, 20)];
        _flabel.textColor=[UIColor redColor];
    }
    return _flabel;
}
@end

model.h

@interface Model : NSObject
@property(nonatomic,strong)NSString*arrimg;
@property(nonatomic,strong)NSString*arrzlabel;
@property(nonatomic,strong)NSString*arrflabel;
+(NSMutableArray *)getDataSource;

model.m

#import "Model.h"

@implementation Model
+(NSMutableArray *)getDataSource{
NSArray*array=@[@{@"arrimg":@"1.png",@"arrzlabel":@"dsgs",@"arrflabel":@"123.00"},@{@"arrimg":@"2.png",@"arrzlabel":@"dsgs",@"arrflabel":@"123.00"},@{@"arrimg":@"1",@"arrzlabel":@"dsgs",@"arrflabel":@"123.00"},@{@"arrimg":@"2",@"arrzlabel":@"dsgs",@"arrflabel":@"123.00"},@{@"arrimg":@"1",@"arrzlabel":@"dsgs",@"arrflabel":@"123.00"},@{@"arrimg":@"1",@"arrzlabel":@"dsgs",@"arrflabel":@"123.00"}];
    
    NSMutableArray*dataSource=[NSMutableArray new];
    
    for (NSDictionary*dic in array) {
        Model*mod=[Model new];
        [mod setValuesForKeysWithDictionary:dic];
        [dataSource addObject:mod];
    }
    return dataSource;
    
}
@end

视频界面

#import "shipinViewController.h"
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
@interface shipinViewController ()

@end

@implementation shipinViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView*view=[[UIView alloc] initWithFrame:self.view.frame];
    UIButton*btn=[[UIButton alloc] initWithFrame:self.view.frame];
    [btn setImage:[UIImage imageNamed:@"屏幕快照 2018-11-22 下午4.57.16.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventAllEvents];
    [self.view addSubview:view];
    [view addSubview:btn];
}
-(void)click{
    //获取本地视频
    NSString *file = [[NSBundle mainBundle]pathForResource:@"来了老弟.mp4" ofType:nil];
    //创建播放器
    AVPlayerViewController *player = [[AVPlayerViewController alloc]init];
    
    player.player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:file]];
    
    [self presentViewController:player animated:YES completion:nil];
    
    [player.player play];
}
//即将显示
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //隐藏原有导航
    self.tabBarController.tabBar.hidden=YES;
}
//视图将要消失
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    //显示导航
    self.tabBarController.tabBar.hidden=NO;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值