iOS---》点击uitableview 的section展开或隐藏
#import <UIKit/UIKit.h> @interface TestCell : UITableViewCell @property (weak, nonatomic) IBOutlet UILabel *firstLabel; @property (weak, nonatomic) IBOutlet UILabel *endLabel;
@property (weak, nonatomic) IBOutlet UIView *myView; @end
#import "TestCell.h" @implementation TestCell - (void)awakeFromNib {
_myView.layer.borderColor=[UIColor clearColor].CGColor; // Initialization code
} - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated]; // Configure the view for the selected state
} @end #import "ViewController.h"
#import "TestCell.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{ NSMutableArray *rowArray;
BOOL *flag;
}
@property (weak, nonatomic) IBOutlet UITableView *myTableView; @end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad]; rowArray=[NSMutableArray arrayWithObjects:@"",@"",@"", @"",@"",@"",@"",@"",@"",nil];
flag = (BOOL*)malloc(rowArray.count*sizeof(BOOL*));
memset(flag, NO, sizeof(*flag));
//_myTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
// Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return rowArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (flag[section]) {
return rowArray.count;
}
else
{
return ;
} }
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ TestCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TestCell"];
cell.firstLabel.text=rowArray[indexPath.row];
cell.endLabel.text=rowArray[indexPath.row]; return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section==) {
return [self firstView];
} return [self sectionView:section];
}
-(UIView *)firstView
{
UIView *contentView=[[UIView alloc]initWithFrame:CGRectMake(, , , )];
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(, , , )];
label.text=@"--1--";
[contentView addSubview:label];
return contentView;
}
-(UIView *)sectionView:(NSInteger)section
{
UIView *contentView=[[UIView alloc]initWithFrame:CGRectMake(, , , )];
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(-, , , );
btn.tag=section;
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(, , , )];
label.text=@"测试";
if(flag[section])
{
[ btn setBackgroundImage:[UIImage imageNamed:@"open"] forState:UIControlStateNormal];
}
else
{
[ btn setBackgroundImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
}
[contentView addSubview:btn];
[contentView addSubview:label];
contentView.layer.borderColor=[UIColor lightGrayColor].CGColor;
contentView.layer.borderWidth=1.0;
contentView.alpha=1.0;
return contentView; }
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return ;
}
-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
}
-(void)btnClick:(UIButton *)sender
{
int index=(int)sender.tag;
flag[index]=!flag[index];
[_myTableView reloadData];
} @end

iOS---》点击uitableview 的section展开或隐藏的更多相关文章
- 点击UITableView的cell展开收缩
在项目中有个需求,点击表视图的单元格展开,再点击另外一个单元格或者本身又收缩,经过一段时间尝试,实现了该功能,现在记录分享总结下. 首先要理解UITableView代理方法调用的先后顺序. 当 ...
- ios知识点总结——UITableView的展开与收缩及横向Table
UITableVIew是iOS开发中使用最为广泛的一种控件,对于UITableView的基本用法本文不做探讨,本文主要是针对UITableView的展开与收缩进行阐述,在文章的后面也会探讨一下横向ta ...
- iOS开发——UI_swift篇&UITableView实现单元格展开与隐藏
UITableView实现单元格展开与隐藏 关于UITableView的展开的收缩在前面的文章我已经结束,就是使用代理,通知,block传值的时候实现的,当时是使用一个Bool值来实现,最后使用着三 ...
- Swift - 实现点击UITableView单元格时自动展开单元格
下面是一个列表单元格cell的折叠展开效果的demo.当点击单元格时会展开该单元格,便于显示一些详情什么的.点击其他单元格原来的会关闭,同时有动画效果. 效果如如下: 代码如下: 1 2 3 4 ...
- iOS开发系列--UITableView全面解析
--UIKit之UITableView 概述 在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似于微信.QQ.新浪微博等软件基本上随处都是U ...
- iOS 点击cell下拉
iOS 点击cell下拉 代码如下: #import "ViewController.h" @interface ViewController ()<UITableView ...
- UITableView:可展开的 UITableView
针对 TableView,有些时候需要在点击 cell 时,展开这行 cell,显现出更多的选项或者全部内容等. 比较容易想到的处理方案就是利用 section,在未选择之前,每一行都是一个 sect ...
- iOS开发之UITableView的使用
这一篇记录的是iOS开发中UITableView的使用,iOS中的UITableView跟Android中的ListView特别相似,以下用一个Demo来说明: 1.Xcode中新建projectTe ...
- iOS Programming Editing UITableView
iOS Programming Editing UITableView 1.1 Editing mode UITableView has an editing property, and when ...
随机推荐
- 安装CiscoWorks LMS
安装CiscoWorks LMS,需要安装5张光盘,CiscoWorks LMS的安装步骤比较简单,在这里只介绍需要的重要步骤. 1.安装CD One 将CiscoWorks 2000 LMS CD ...
- PPPOE拨号演练
搭建PPPOE服务器,拓扑如下 PPP-Server配置如下: (config)#bba-group pppoe global (config-bba-group)#virtual-template ...
- CCF 201312-5 I’m stuck! (暴力,BFS)
问题描述 给定一个R行C列的地图,地图的每一个方格可能是'#', '+', '-', '|', '.', 'S', 'T'七个字符中的一个,分别表示如下意思: '#': 任何时候玩家都不能移动到此方格 ...
- (《数论及应用1.3》NEFU 116 两仪剑法(最小公倍数&&最大公约数))
#include <iostream> using namespace std; long long gcd(long long a, long long b){ if(b == 0){ ...
- OC: Block回调的使用demo
Block 的用法 对于类的继承问题,子类在实现的时候,一般是自下而上,先看看下面的实现没有,没实现就向上找方法去实现. // // main.m #import <Foundation/Fou ...
- C++静态成员函数小结 [转]
类中的静态成员真是个让人爱恨交加的特性.我决定好好总结一下静态类成员的知识点,以便自己在以后面试中,在此类问题上不在被动. 静态类成员包括静态数据成员和静态函数成员两部分. 一 静态数据成员: 类体中 ...
- javascript数字转汉字中文数字
/* 工具包 */ var Utils={ /* 单位 */ units:'个十百千万@#%亿^&~', /* 字符 */ chars:'零一二三四五六七八九', /* 数字转中文 @numb ...
- cocos2dx libcurl
转自:http://www.himigame.com/curl-libcurl/878.html 本篇介绍使用libcurl编程的一般原则和一些基本方法.本文主要是介绍 c 语言的调用接口,同时也可能 ...
- python学习进阶一
map()函数 def format_name(s): return s.capitalize() print map(format_name, ['adam', 'LISA', 'barT']) R ...
- Objective-C语法之代码块(block)的使用
代码块本质上是和其它变量相似.不同的是,代码块存储的数据是一个函数体.使用代码块是,你能够像调用其它标准函数一样,传入參数数,并得到返回值. 脱字符(^)是块的语法标记.依照我们熟悉的參数语法规约所定 ...