/**
初始化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. struts自定义拦截器

    第01步:配置web.xml,启动struts框架 <?xml version="1.0" encoding="UTF-8"?> <web-a ...

  2. 关于Linux系统basename函数缺陷的思考

    某模块作为前台进程独立运行时,运行命令携带命令行参数:作为某平台下守护进程子进程运行时,需要将命令行参数固化在代码里.类似如下写法: char *argv[] = {"./DslDriver ...

  3. 狗屁不通的“视频专辑:零基础学习C语言(小甲鱼版)”(2)

    前文链接:狗屁不通的“视频专辑:零基础学习C语言(小甲鱼版)”(1) 小甲鱼在很多情况下是跟着谭浩强鹦鹉学舌,所以谭浩强书中的很多错误他又重复了一次.这样,加上他自己的错误,错谬之处难以胜数. 由于拙 ...

  4. PHP用正则批量替换Img中src内容,用正则表达式获取图片路径实现缩略图功能

    PHP用正则批量替换Img中src内容,用正则表达式获取图片路径实现缩略图功能 网上很多正则表达式只能获取或者替换一个img的src内容,或者只能替换固定的字符串,要动态替换多个图片内容的试了几个小时 ...

  5. 调用css时,用link 和 @import url 有什么区别

    加载css link与@import的区别: 其实 link 与 @import 在显示效果上还是有很大区别的,基本上来看 link 的加在会在页面显示之前全部加在完全,而 @import 会是读取完 ...

  6. SuperSocket架构设计示意图【转】

    转自:http://docs.supersocket.net/v1-6/zh-CN/Architecture-Diagrams 中文(中国)Toggle Dropdown v1.6Toggle Dro ...

  7. readonly/disable input 问题

    Perhapes for surity, in chrome and IE10, readonly/disabled input will be reset when the form submit. ...

  8. [转]Dynamics AX and Generic collections of .Net

    转自:http://blogs.msdn.com/b/emeadaxsupport/archive/2009/04/23/dynamics-ax-and-generic-collections-of- ...

  9. Entrust是一种为Laravel5添加基于角色的权限的简洁而灵活的方法。

    安装 首先要在composer.json中添加: "zizaco/entrust": "5.2.x-dev" 然后运行composer install 或者 c ...

  10. api(接口)文档管理工具

    api(接口)文档管理工具 欢迎光临:博之阅API管理平台  ,做为一个app开发者,还没有用到api管理工具,你就OUT了 点击进入:程序员精华博客大全