层叠选择框的实现(实现方法参照本博客的下拉列表)
来源:互联网 发布:男女合租 知乎 编辑:程序博客网 时间:2024/05/01 04:32
如下图,这种点击可以展开详细列表的集合视图,下面阐释一种简单的实现方法:
实现思路如下:
A.首先,给集合视图初始化N个分区,给每个分区用一个布尔值参数来判断该分区是否需要展开详细列表,初始的时候,每个分区返回的cell个数是0,即不展开。
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (!_isOpen[section]) {
return0; }
else{
return [[self.allClassArrayobjectAtIndex:section]count];
}}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return4;
}
B.然后,给集合视图返回分区头的方法中添加具有点击手势的UIView,来实现点击该分区头时展开列表的功能。分区头的高度需要设置一下,否则不显示。
//表头(增广视图)
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
NSArray *titleArray =@[@"来源",@"状态",@"性别",@"咨询师"];
ClassCollectionReusableView *singerView = [collectionViewdequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"collectionHeader"forIndexPath:indexPath];
singerView.title.text = titleArray[indexPath.section];
UITapGestureRecognizer *alphaTap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(TapSection:)];
singerView.tag = indexPath.section +10;
[singerView addGestureRecognizer:alphaTap];
//此处是控制分区头右侧的箭头的图,可忽略
if ( !_isOpen[singerView.tag-10]) {
[singerView.btnsetImage:[UIImageimageNamed:@"buy_jiantou_d@2x"]forState:UIControlStateNormal];
}else{
[singerView.btnsetImage:[UIImageimageNamed:@"buy_jiantou_u@2x"]forState:UIControlStateNormal];
}
return singerView;
}
//增广视图size设置
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
returnCGSizeMake(kWidth -30,40);
}
- (void)TapSection:(UITapGestureRecognizer *)tap {
//实现功能一:只打开一个分区,其他section隐藏
for (int i=0; i<4; i++) {
_isOpen[i]=0;
}
_isOpen[tap.view.tag-10]=1;
//实现功能二:可以打开多个分区
// _isOpen[tap.view.tag-10]= !_isOpen[tap.view.tag-10];
NSLog(@"TapAction");
//最后刷新集合视图
[adView.selectViewreloadData];
}
- 层叠选择框的实现(实现方法参照本博客的下拉列表)
- 下拉列表的左右选择的实现
- javascript实现下拉列表框选择时另一下拉列表框的值相应变化
- 实现下拉列表的一种方法
- 【php】深入探讨php下拉框选择的实现方法
- 深入探讨PHP下拉框选择的实现方法
- 实现HTML下拉列表中不能选择的项
- 下拉列表框只能选择,我想选择后还可以允许用户对选择的内容进行修改,如何实现可编辑的下拉列表框?
- Java实现的自定义可编辑表格控件(支持汇总、滚动、增行、删行、小数、日期、下拉列表、参照等)
- Excel实现下拉列表选择
- 实现带复选框的下拉列表
- 二级下拉列表的实现
- 二级下拉列表的实现
- ALV 下拉列表的实现
- 下拉刷新列表的实现
- 级联下拉列表的实现
- 下拉选择框的代码实现
- 如何用C#实现Word里的字体选择下拉列表框!
- Ajax 完整教程
- text-align:justify实现两端对齐
- Oracle知识点
- js字符串截取函数slice()、substring()、substr()
- 单点登录
- 层叠选择框的实现(实现方法参照本博客的下拉列表)
- 带条件的Insert语句
- Xcode7 如何使用代码对齐插件XAlign
- python第十一天学习记录
- 如何把工程部署在Tomcat上
- 如何在vmware中安装mac OS系统
- xUtils3的简单介绍
- kali 2016.2 安装vm-tools
- 前后端分离的探索(二)