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 ... 
随机推荐
- postconf 命令常用参数
			postfix的main.cf配置文件一般不直接编辑,而多使用postconf命令来配置‘ postconf -d:查看默认配置: postconf -n:查看当前配置(即当前生效的配置): post ... 
- python报错ordinal not in range(128)
			python编码问题:'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128) 这种问题有三种原因: ... 
- winform 映射字段的写法:
			public partial class FrmFieldMapping : DevComponents.DotNetBar.Office2007Form { private AMDataFieldC ... 
- CodeForces 710A  King Moves (水题)
			题意:给定一个坐标,问你皇后有几个方向可以走. 析:直接格举那八个方向即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000 ... 
- HDU 5443 The Water Problem (水题,暴力)
			题意:给定 n 个数,然后有 q 个询问,问你每个区间的最大值. 析:数据很小,直接暴力即可,不会超时,也可以用RMQ算法. 代码如下: #include <cstdio> #includ ... 
- CreateEvent的用法
			事件对象就像一个开关:它只有两种状态---开和关.当一个事件处于”开”状态,我们称其为”有信号”否则称为”无信号”.可以在一个线程的执行函数中创建一个事件对象,然后观察它的状态,如果是”无信号”就让该 ... 
- MD5加密类方法
			package com.shkj.android.utils; import java.security.MessageDigest;import java.security.NoSuchAlgori ... 
- Notes on Probabilistic Latent Semantic Analysis (PLSA)
			转自:http://www.hongliangjie.com/2010/01/04/notes-on-probabilistic-latent-semantic-analysis-plsa/ I hi ... 
- 由Tencent://Message协议想到的一个解决方案
			参考网址:http://www.cnblogs.com/phinecos/archive/2009/03/06/1404951.html 源代码下载:http://files.cnblogs.com/ ... 
- (C#)使用队列(Queue)解决简单的并发问题
			(C#)使用队列(Queue)解决简单的并发问题 2015-07-16 13:04 13265人阅读 评论(8) 收藏 举报 分类: Asp.Net(8) 版权声明:本文为博主原创文章,未经博主允 ... 
