#import "ViewController.h"

#define HEIGHT [UIScreen mainScreen].bounds.size.height

#define WIDTH [UIScreen mainScreen].bounds.size.width

@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UIView* backvView;

@property(nonatomic,strong)UIScrollView* secondScrollView;

@property(nonatomic,strong)UICollectionView* collectionView;

@property(nonatomic,strong)UITableView * tableView;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

//添加ui

[self AddUI];

//添加集合视图

[self collectionViewMethods];

//添加单元格

[self tableViewMethods];

}

-(void)AddUI

{

_backvView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-40)];

_backvView.backgroundColor=[UIColor cyanColor];

[self.view addSubview:_backvView];

UIImageView* fristImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 520.0/2208.0*HEIGHT)];

fristImageView.backgroundColor = [UIColor yellowColor];

[_backvView addSubview:fristImageView];

_secondScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 520.0/2208.0*HEIGHT, WIDTH, 640.0/2208.0*HEIGHT)];

_secondScrollView.backgroundColor=[UIColor blueColor];

[_backvView addSubview:_secondScrollView];

UIView * thirdView=[[UIView alloc]initWithFrame:CGRectMake(0, 1160.0/2208.0*HEIGHT, WIDTH,30.0/2208.0*HEIGHT)];

thirdView.backgroundColor=[UIColor colorWithRed:236/255.0 green:236/255.0 blue:236/255.0 alpha:1];

[_backvView addSubview:thirdView];

UIView* fourthView=[[UIView alloc]initWithFrame:CGRectMake(0, 1190.0/2208.0*HEIGHT, WIDTH, 830.0/2208.0*HEIGHT)];

fourthView.backgroundColor=[UIColor greenColor];

[_backvView addSubview:fourthView];

UIView* fifthView=[[UIView alloc]initWithFrame:CGRectMake(0, 2010.0/2208.0*HEIGHT, WIDTH, 45.0/2208.0*HEIGHT)];

fifthView.backgroundColor=[UIColor colorWithRed:236/255.0 green:236/255.0 blue:236/255.0 alpha:1];

[_backvView addSubview:fifthView];

}

-(void)tableViewMethods

{

_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];

_tableView.delegate=self;

_tableView.dataSource=self;

[self.view addSubview:_tableView];

_tableView.tableHeaderView=_backvView;

}

-(void)collectionViewMethods

{

//初始化集合视图对象

UICollectionViewFlowLayout* layout=[[UICollectionViewFlowLayout alloc]init];

//设置集合视图滚动方向

[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];

//设置item的大小

[layout setItemSize:CGSizeMake(150.0/1242.0*WIDTH, 150.0/2208.0*HEIGHT)];

//设置集合视图的范围   距离边距   依次是上左下右

[layout setSectionInset:UIEdgeInsetsMake(70.0/2208.0*HEIGHT, 70.0/1242.0*WIDTH, 100.0/2208.0*HEIGHT, 70.0/1242.0*WIDTH)];

//设置最小行间距

layout.minimumLineSpacing = 90.0/1242.0*WIDTH;

//最小列间距

layout.minimumInteritemSpacing = 60.0/2208.0*HEIGHT;

[self setCollectionView:[[UICollectionView alloc]initWithFrame: CGRectMake(0, 0, WIDTH, 640.0/2208.0*HEIGHT)collectionViewLayout:layout]];

[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];

_collectionView.delegate = self;

_collectionView.dataSource = self;

_collectionView.backgroundColor = [UIColor whiteColor];

[_secondScrollView addSubview:_collectionView];

}

#pragma mark -UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return 10;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

//创建一个静态的字符串  当作单元格的标记

static NSString* cellId=@"cell";

//先表格视图的单元格池        中获取有该标记的单元格  获取到的单元格上暂时没有被使用的

UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:cellId];

if (cell==nil)

{

cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];

}

return cell;

}

#pragma mark -UICollectionViewDelegate

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

return 20;

}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{

UICollectionViewCell* cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

[cell setBackgroundColor:[UIColor colorWithRed:arc4random () % 255 /255.0 green:arc4random () % 255 /255.0 blue:arc4random () % 255 /255.0 alpha:1]];

return cell;

}

@end

collectionView 和 tableView的嵌套使用的更多相关文章

  1. 关于collectionView和tableView的两种cell的出列方法的区别

    相信好多人一定会对collectionView和tableView的两种cell出列方法有所疑问,下面以UICollection为例子进行举例说明 假设我们已经创建了一个collectionView, ...

  2. OC CollectionView和TableView自身高度的隐式递归计算,改变父试图布局

    CollectionView和TableView自身高度的隐式递归计算 1.前沿:我们一般会碰到这样的需求,一个tableview或者一个colletionview放在一个scrollview上边,而 ...

  3. tableView的嵌套

    1,subTableView需要开启多手势识别,多层tableView都会响应滚动事件(如果底层是scroll 依然会响应,这样滚动tableview时,scroll也会滚动,导致滚动过于灵活)2,通 ...

  4. tableView嵌套collectionView

    首先是自定义collectionView填充的tableViewCell import UIKit // 定义一个collectionView,重写初始化大小和布局方法 class TrendsDet ...

  5. ios中自定义tableView,CollectionView的cell什么时候用nib加载,什么时候用标识重用

    做了一段时间的iOS,在菜鸟的路上还有很长的路要走,把遇到的问题记下来,好记性不如烂笔头. 在项目开发中大家经常会用到tableView和collectionView两个控件,然而在cell的自定义上 ...

  6. ios 两个 TableView 之间的联动, TableView 与 CollectionView 之间的联动

    两个 TableView 之间的联动, TableView 与 CollectionView 之间的联动 这是一个创建于 359 天前的主题,其中的信息可能已经有所发展或是发生改变. [联动] :两个 ...

  7. ios开发之-- tableview/collectionview获取当前点击的cell

    方法如下: 一般collectionView 或者 tableview都有自带的点击函数,如下: , collectionView -(void)collectionView:(UICollectio ...

  8. iOS tableView嵌套部分WebView效果实现

    对于一些资讯类的app,比如网易新闻,今日头条这样的,他们的文章详情页大部分基本都是tableView中嵌套webView来实现的效果,其中顶部标题,关注按钮等这些可能是原生的,内容部分是webVie ...

  9. iOS开发 爱特开发技术bug总结

    #pragma mark 每天总结学习两小时  效率 和 每天学习 研究底层 多进去看看 // .................................................... ...

随机推荐

  1. Python数据类型及其方法详解

    Python数据类型及其方法详解 我们在学习编程语言的时候,都会遇到数据类型,这种看着很基础也不显眼的东西,却是很重要,本文介绍了python的数据类型,并就每种数据类型的方法作出了详细的描述,可供知 ...

  2. 【ASP.NET MVC 牛刀小试】 URL Route

    例子引入 先看看如下例子,你能完全明白吗? using System; using System.Collections.Generic; using System.Linq; using Syste ...

  3. cache 和 buffer的区别

    cache 和 buffer的区别: Cache:高速缓存,是位于CPU与主内存间的一种容量较小但速度很高的存储器.由于CPU的速度远高于主内存, CPU直接从内存中存取数据要等待一定时间周期,Cac ...

  4. java网络编程之socket(2)

    异步处理多客户端连接服务端 上篇讲到的是服务端接收一个客户端的请求之后就结束了,不能再接收其他客户端的请求了,实际情况上我们希望服务端能够处理来自不同用户的请求. 想到这里,或许我们可以用一个死循环, ...

  5. 通过线程监控socket服务器是否done机

    现实中的socket可能会因为各种原因done机,但这么重要的服务器怎么能允许这种事情发生?这次我们就来通过一个线程去监控socket服务器,如果done机重新将其启动. 下面是监控项目和socket ...

  6. Scratch2的离线下载与安装

    scratch是一种程序设计语言,可以用来设计 故事.动画.游戏.音乐和美术作品. Scratch主页:https://scratch.mit.edu/ Scratch的下载与安装: 首先下载并安装A ...

  7. 在Visual Studio 2017中使用Asp.Net Core构建Angular4应用程序

    前言 Visual Studio 2017已经发布了很久了.做为集成了Asp.Net Core 1.1的地表最强IDE工具,越来越受.NET系的开发人员追捧. 随着Google Angular4的发布 ...

  8. bcp和load table

    使用BCP和LOAD TABLE联合完成Sybase IQ 的数据导出和导入工作.说明: 表(视图)GN_TEST只有两个字段,TIMEID和MSISDN, 导出时我用'|'作为字段分隔符,'& ...

  9. Maven下从HDFS文件系统读取文件内容

    需要注意以下几点 1.所以的包都是org.apache.hadoop.XXX 2.三个配置文件要放到指定文件夹中等待文件系统读取(src/main/resources):core-site.xml h ...

  10. 解决element-ui 中upload组件使用多个时无法绑定对应的元素

    问题场景 我们在一个列表中分别都需要有upload组件的时候也就涉及到了多个upload同时存在: 因为一般可以在success回调中拿到上传成功的图片已经成功的response,多个也可以,这个没毛 ...