//
// ViewController.m
// 222
//
// Created by 三哥哥 on 2018/11/1.
// Copyright © 2018年 三哥哥. All rights reserved.
//
#import “ViewController.h”
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>{
UITableView *tab;
}
@end
static NSString *coll=@“112”;
@implementation ViewController
-
(void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.barTintColor=[UIColor blackColor];
self.navigationItem.title=@“数码科技”;
self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:16]};
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@“➕” style:UIBarButtonItemStyleDone target:self action:@selector(rightButton)];
tab=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
tab.delegate=self;
tab.dataSource=self;[self.view addSubview:tab];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(section0){
return 2;
}else{
return 6;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cc=@“11”;
UITableViewCell *cell=[tab dequeueReusableCellWithIdentifier:cc];
if(!cell){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cc];
}
if(indexPath.section0){
if(indexPath.row==0){
tab.rowHeight=150;
UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
img.image=[UIImage imageNamed:@“京东头视图”];
[cell addSubview:img];}else{ tab.rowHeight=100; //初始化流水布局 UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new]; //设置格子的大小 layout.itemSize = CGSizeMake(100, 100); //设置最小行间距 layout.minimumLineSpacing = 1; //设置最小列间距 layout.minimumInteritemSpacing = 1; //设置i网格
// layout.sectionInset=UIEdgeInsetsMake(10, 10, 10, 20);
//创建网格
UICollectionView *colV = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100) collectionViewLayout:layout];
colV.backgroundColor = [UIColor lightGrayColor];
//设置数据源 代理
colV.delegate = self;
colV .dataSource = self;
//停止滚动
colV.scrollEnabled = NO;
//注册网格
[colV registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:coll];
[cell addSubview:colV];
//
}
}else{
}
return cell;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 3;
}
//设置cell内容
-
(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//重用
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:coll forIndexPath:indexPath];//设置cell内容
UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 40, 40)];
NSArray *arr1 = @[@“1.jpg”,@“3.jpg”,@“3.jpg”];
//设置图片
imgV.image = [UIImage imageNamed:arr1[indexPath.row]];
//将图片添加到cell
[cell addSubview:imgV];
return cell;
}
-(void)rightButton{
NSLog(@“点击了!”);
}