iOS tableview cell 的展开收缩
iOS tableview cell 的展开收缩
#import "ViewController.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>{
NSMutableArray *_allArray;//创建一个数据源数组
NSMutableDictionary *dic;//创建一个字典进行判断收缩还是展开
}
@property (nonatomic,strong)UITableView *tableView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
dic = [NSMutableDictionary dictionary];
_allArray = [@[@[@"12",@"32",@"12",@"12",@"12",@"32"],@[@"12",@"12",@"12",@"32",@"12",@"12",@"12",@"32",@"12",@"12",@"12",@"32"],@[@"12",@"12",@"32"]]mutableCopy];
[self.view addSubview:self.tableView];
}
//懒加载
- (UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0, 64, 375, 667 - 64)style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
}
return _tableView;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{
return _allArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 30;
}
//
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [UIView new];
view.backgroundColor = [UIColor redColor];
//创建一个手势进行点击,这里可以换成button
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:self action:@selector(action_tap:)];
view.tag = 300 + section;
[view addGestureRecognizer:tap];
return view;
}
- (void)action_tap:(UIGestureRecognizer *)tap{
NSString *str = [NSStringstringWithFormat:@"%ld",tap.view.tag - 300];
if ([dic[str] integerValue] == 0) {//如果是0,就把1赋给字典,打开cell
[dic setObject:@"1" forKey:str];
}else{//反之关闭cell
[dic setObject:@"0" forKey:str];
}
// [self.tableView reloadData];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[str integerValue]]withRowAnimation:UITableViewRowAnimationFade];//有动画的刷新
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSString *string = [NSStringstringWithFormat:@"%ld",section];
if ([dic[string] integerValue] == 1 ) { //打开cell返回数组的count
NSArray *array = [NSArrayarrayWithArray:_allArray[section]];
return array.count;
}else{
return 0;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 35;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleValue1reuseIdentifier:@"cell"];
}
cell.backgroundColor = [UIColor orangeColor];
cell.textLabel.text = _allArray[indexPath.section][indexPath.row];
return cell;
}
@end
iOS tableview cell 的展开收缩的更多相关文章
- [IOS Tableview] cell自定义view显示错误问题
问题介绍:按照tableviewcell的tag自定义cell的view显示的时候,会出现拖动时显示错误情况(在Tableview的范围超出屏幕范围需要滑动的情况下). 我做的是一个下载界面,我为了简 ...
- 点击UITableView的cell展开收缩
在项目中有个需求,点击表视图的单元格展开,再点击另外一个单元格或者本身又收缩,经过一段时间尝试,实现了该功能,现在记录分享总结下. 首先要理解UITableView代理方法调用的先后顺序. 当 ...
- iOS - (TableView中利用系统的 cell 设置 cell.textlabel 位置和大小)
今天工作稍微的遇到了一点小小的难题,需求效果中 TableView cell 中的 Label 字体大小比原先系统中的要大些且 Label 位置不是在前面,而是在中间往后,对于这个问题我第一时间也是想 ...
- iOS TableView多级列表
代码地址如下:http://www.demodashi.com/demo/15006.html 效果预览 ### 一.需求 TableView多级列表:分级展开或合并,逐级获取并展示其子级数据,可以设 ...
- SlickGrid example 5:带子项的展开收缩
带子项的展开收缩. 代码: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Ty ...
- ios tableview 上加 textfiled
ios tableview 上加 textfiled 首先附上我项目中用曾经用到的几张图 并说明一下我的用法: 图1: 图2: 图3: 心在你我说一下 我当初的实现 方法 ,希望能给你们一些 启 ...
- iOS解决cell重用问题
在写sina 微博界面的过程中使用到了cell,那么就是在cell上添加一些控件,但是由于每条微博的内容都是不同的,所以在显示的过程中,出现了内容重叠的问题,其实就是UITableViewCell重用 ...
- 修改mui accordion(折叠面板)默认展开收缩行为
mui的折叠面板 accordion 默认展开收缩逻辑是,展开其中一个的同时收缩起同级已经展开的元素. 实际需求:展开其中一个不必收缩同级元素. 分析mui.js源代码: window.addEven ...
- iOS 在cell中使用倒计时的处理方法(新)
一.前言 之前的文章iOS 在cell中使用倒计时的处理方法得到大量的支持, 在这先感谢大家的支持. 但是也收到不少人的回复表示不会用, 需要一一解答, 由于之前写的时候没有使用Markdown编辑, ...
随机推荐
- CE工具里自带的学习工具--第四关
图解:
- JavaScript异步编程解决方案探究
javascript的天生单线程特性,使得异步编程对它异常重要,早期的通常做法是用回调函数来解决.但是随着逻辑的复杂,和javascript在服务端的大显神通,使得我们很容易就陷入“回调陷井”的万丈深 ...
- 动态规划----最长公共子序列(C++实现)
最长公共子序列 题目描述:给定两个字符串s1 s2 … sn和t1 t2 … tm .求出这两个字符串的最长公共子序列的长度.字符串s1 s2 … sn的子序列指可以表示为 … { i1 < i ...
- python 3 廖雪峰博客笔记(一) python特性
python 是一种解释性语言,代码在执行时会一行一行翻译成CPU能理解的机器语言. python 的特点是简单优雅. python 的优点是 代码优雅 基础代码库丰富,包括网络.文件.GUI.数据库 ...
- CF1000G Two-Paths
题目大意:给你一棵树,其中点上和边上都有值.定义2-Path为经过一条边最多两次的路径,价值为经过点的权值加和-经过边权值*该边经过次数.4e5组询问,每次询问树上连接x,y两点的2-Path的最大价 ...
- Kvm:通过 libvirt 远程管理虚拟机
1.通过qemu+ssh方式 2.通过qemu+tcp方式 主控端需要安装相关工具包: #yum groupinstall "Virtualization" #yum instal ...
- ACdream 1063 字典树
ACdream 1063 字典树 平衡树 神奇的cxlove有一颗平衡树,其树之神奇无法用语言来描述 OrzOrz. 这棵树支持3种操作: 1.加入一个数到树中,维护平衡树的合法性: 2.给一个数X, ...
- 【Codeforces 1086B】Minimum Diameter Tree
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 统计叶子节点个数m 把每条和叶子节点相邻的边权设置成s/cnt就可以了 这样答案就是2*s/m(直径最后肯定是从一个叶子节点开始,到另外一个叶 ...
- 【Codeforces 231C】To Add or Not to Add
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 把数组排个序, 显然优先用大的且小于枚举的数字a[i]的数字变成a[i] 那么肯定有一个范围j. 然后a[j~i-1]都能在k花费以内变成a[ ...
- Web页面测试总结(控件类)
界面测试,最多的就是各种控件的功能测试,只有掌握了其测试要点,了解测试方法,总结各种测试情景,才能熟练测试Web页面. 一.输入框 输入框分为文本输入框,数字输入框.一般使用在填写输入的内容上,比如名 ...