/**
初始化UICollectionView
*/
UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
flowLayout.minimumLineSpacing = ;
flowLayout.minimumInteritemSpacing=; _deviceCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(, , kScreenWidth, kHeightPro()*) collectionViewLayout:flowLayout]; //设置代理
_deviceCollectionView.delegate = self;
_deviceCollectionView.dataSource = self;
[self.view addSubview:_deviceCollectionView];
[_deviceCollectionView setBackgroundColor:RGBColor(0xf3, 0xf6, 0xf8)]; // Register cell classes
[_deviceCollectionView registerClass:[AnbotDeviceCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
#pragma mark -- <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return ;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return ;
} - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { AnbotDeviceCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
[cell sizeToFit];
if (!cell) {
NSLog(@"无法创建CollectionViewCell时打印,自定义的cell就不可能进来了。");
}
[self configureCell:cell atIndexPath:indexPath]; return cell;
} - (void)configureCell:(AnbotDeviceCollectionViewCell *)cell atIndexPath:(NSIndexPath*)indexPath
{ int index = indexPath.row *+ indexPath.section;
cell.section = indexPath.section;
[cell setEnableImage:UIResourceBundleSubDevice(imageOpenArr[index])];
[cell setDisableImage:UIResourceBundleSubDevice(imageCloseArr[index])];
// [cell setImage:UIResourceBundleSubDevice(imageOpenArr[index])]; [cell setNameText:titleArr[index]]; [cell setDeviceNum:[devCountArr[index]integerValue]];
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
} -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(, , , );
} - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{ return CGSizeMake(kScreenWidth/, collectionView.frame.size.height/);
} - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
// NSLog(@"cell #%d was selected %d", indexPath.row,indexPath.section); int index = indexPath.row *+ indexPath.section;
if ([devCountArr[index] integerValue]==) {
return;
} NSPredicate *predicate = [NSPredicate predicateWithFormat:@" deviceType == %d ",index];
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:deviceArr];
[tempArray filterUsingPredicate:predicate];
AnbotSingleDeviceManagerVC *singleVC = [[AnbotSingleDeviceManagerVC alloc]init];
singleVC.index = index; //indexPath.row *2+ indexPath.section;
singleVC.singleDevArr = tempArray;
// singleVC.devInfo = deviceArr[index];
[self.navigationController pushViewController:singleVC animated:YES]; }

UICollectionView 使用的更多相关文章

  1. 【iOS】Xcode8+Swift3 纯代码模式实现 UICollectionView

    开发环境 macOS Sierra 10.12.Xcode 8.0,如下图所示: 总体思路 1.建立空白的storyboard用于呈现列表 2.实现自定义单个单元格(继承自:UICollectionV ...

  2. 使用UICollectionView实现首页的滚动效果

    实现类似这样的效果,可以滚动大概有两种实现方案 1. 使用scrollview来实现 2. 使用UICollectionView来实现 第一种比较简单,而且相对于性能来说不太好,于是我们使用第二种方案 ...

  3. 用NSCalendar和UICollectionView自定义日历,并实现签到显示

    前一段时间因为工作需要实现了一个可以签到的日历,来记录一下实现的思路 效果如图:   这里的基本需求是: 1,显示用户某个月的签到情况,已经签到的日子打个圈,没有签到且在某个时间范围内的可以签到,其他 ...

  4. UICollectionView布局cell的三种方式

    UICollectionViewFlowLayout里面: // 方法一 - (void)prepareLayout{} // 方法二 - (nullable NSArray<__kindof ...

  5. 【Swift】iOS UICollectionView 计算 Cell 大小的陷阱

    前言 API 不熟悉导致的问题,想当然的去理解果然会出问题,这里记录一下 UICollectionView 使用问题. 声明  欢迎转载,但请保留文章原始出处:)  博客园:http://www.cn ...

  6. UICollectionLayout布局 —— UIKit之学习UICollectionView记录二《流水布局》

    重点知识 一. 加载collectionView注意事项 1.创建collectionView,有两种方式 :一种是xib和一种是纯代码:设置代理和数据源,注册cell,配置流水布局的属性,如上.下. ...

  7. UICollectionView中使用 UICollectionViewFlowLayout进行布局(模仿苹果相册)

    现在都知道,在初始化UICollectionView的时候,必须要传入一Layout对象,进行布局管理.这也是collectionview和tableview的明显区别,通过collectionvie ...

  8. UI第十九节——UICollectionView

    UICollectionView其实就是UITableView的升级版,在布局方面比UITableView更出色.下面,先看代码吧 #import "RootViewController.h ...

  9. iOS6新特征:UICollectionView介绍

    http://blog.csdn.net/eqera/article/details/8134986 1.1. Collection View 全家福: UICollectionView, UITab ...

  10. 【iOS】UITabView/UICollectionView 全选问题

    UITabView/UICollectionView 全选问题 SkySeraph July. 30th 2016 Email:skyseraph00@163.com 更多精彩请直接访问SkySera ...

随机推荐

  1. jsformat插件

    Package Control Package Control 是用来管理 Sublime Text 2 的插件的插件. 也是装完后第一个要安装的插件. 首先打开 ctrl+`, 并在打开的 st2 ...

  2. android复习第二天------布局

    1,在4,0版本前一共有五种布局,且都是ViewGroup的子类分别是 RelativeLayout(相对),AbsoluteLayout(绝对),LinearLayout(线性),FrameLayo ...

  3. paper 80 :目标检测的图像特征提取之(一)HOG特征

    1.HOG特征: 方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视觉和图像处理中用来进行物体检测的特征描述子.它通过计算和统计图像局部区域的 ...

  4. VS2012发布网站详细步骤

    1.打开你的VS2012网站项目,右键点击项目>菜单中 重新生成一下网站项目:再次点击右键>发布: 2.弹出网站发布设置面板,点击<新建..>,创建新的发布配置文件: 输入你自 ...

  5. 大数据量的csv文件如何导入到 sql 数据库

    BULK INSERT dbo.T_test001 FROM 'E:\bus_20160316\bus全量评级及借款编号_20160316.csv' WITH ( FIELDTERMINATOR =' ...

  6. yii2顶部导航使用

    yii2中使用顶部导航的具体方法: 1.视图中调用两个类: use yii\bootstrap\Nav;use yii\bootstrap\NavBar; 2. <?php            ...

  7. 数据库性能优化:SQL索引

    SQL索引在数据库优化中占有一个非常大的比例, 一个好的索引的设计,可以让你的效率提高几十甚至几百倍,在这里将带你一步步揭开他的神秘面纱. 1.1 什么是索引? SQL索引有两种,聚集索引和非聚集索引 ...

  8. 验证(Javascript和正则表达式)

    昨天写了验证(C#和正则表达式),今天又写了个js版的验证.现在贴出来,为了方便自己查阅,同时也希望能给需要的人帮助和一些启发.由于今天才开始接触js,所以可能会有一些错漏,希望大家能批评指正. va ...

  9. 鸟哥的linux私房菜学习记录之账号管理与权限设定

    每个登录者都会取到两个ID,一个使用者ID,一个群组ID

  10. Spring项目启动时执行初始化方法

    一.applicationContext.xml配置bean <bean id="sensitiveWordInitUtil" class ="com.hx.daz ...