#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展开或隐藏的更多相关文章

  1. 点击UITableView的cell展开收缩

    在项目中有个需求,点击表视图的单元格展开,再点击另外一个单元格或者本身又收缩,经过一段时间尝试,实现了该功能,现在记录分享总结下.   首先要理解UITableView代理方法调用的先后顺序.   当 ...

  2. ios知识点总结——UITableView的展开与收缩及横向Table

    UITableVIew是iOS开发中使用最为广泛的一种控件,对于UITableView的基本用法本文不做探讨,本文主要是针对UITableView的展开与收缩进行阐述,在文章的后面也会探讨一下横向ta ...

  3. iOS开发——UI_swift篇&UITableView实现单元格展开与隐藏

    UITableView实现单元格展开与隐藏  关于UITableView的展开的收缩在前面的文章我已经结束,就是使用代理,通知,block传值的时候实现的,当时是使用一个Bool值来实现,最后使用着三 ...

  4. Swift - 实现点击UITableView单元格时自动展开单元格

    下面是一个列表单元格cell的折叠展开效果的demo.当点击单元格时会展开该单元格,便于显示一些详情什么的.点击其他单元格原来的会关闭,同时有动画效果. 效果如如下:   代码如下: 1 2 3 4 ...

  5. iOS开发系列--UITableView全面解析

    --UIKit之UITableView 概述 在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似于微信.QQ.新浪微博等软件基本上随处都是U ...

  6. iOS 点击cell下拉

    iOS  点击cell下拉 代码如下: #import "ViewController.h" @interface ViewController ()<UITableView ...

  7. UITableView:可展开的 UITableView

    针对 TableView,有些时候需要在点击 cell 时,展开这行 cell,显现出更多的选项或者全部内容等. 比较容易想到的处理方案就是利用 section,在未选择之前,每一行都是一个 sect ...

  8. iOS开发之UITableView的使用

    这一篇记录的是iOS开发中UITableView的使用,iOS中的UITableView跟Android中的ListView特别相似,以下用一个Demo来说明: 1.Xcode中新建projectTe ...

  9. iOS Programming Editing UITableView

    iOS Programming Editing UITableView 1.1 Editing mode  UITableView has an editing property, and when ...

随机推荐

  1. C++11角括号

    [C++11角括号] 标准 C++ 的剖析器一律将 ">>" 视为右移运算符. 但在样板定义式中,绝大多数的场合其实都代表两个连续右角括号. 为了避免剖析器误判,撰码时 ...

  2. VoToucher

    VoToucher package com.isoftstone.pcis.policy.common.utils; import com.isoftstone.pcis.policy.common. ...

  3. keil中如何得知所编译程序所占空间大小?

    keil编译后出现Program Size: data=21.0 xdata=0 code=2231. 这表明 data= 21.0  数据储存器内部RAM占用21字节, xdata=0     数据 ...

  4. C#POP3协议实现SSL验证登陆GMAIL

    最近在折腾POP3协议,登陆pop.qq.com和pop.163.com没有什么问题,于是就想着登陆pop.gmail.com,结果失败了.经查,发现gmail的pop3端口不是110,而是995.于 ...

  5. Oracle中wm_concat()函数的使用

    Oracle中wm_concat()函数的使用 wm_concat()函数是oracle行列转换函数,该函数可以把列值以‘,’分割开来,并显示成一行. 1.原数据: 2.把结果分组以‘|’分隔,以一行 ...

  6. 栈的应用-四则表达式(C#代码实现)

    ->概念 中缀表达式 9+(3-1)*3+10/2 转换步骤 9 + 9 + ( 9 3 + ( - 9 3 1 + ( - ) 9 3 1 - + 9 3 1 - + * 9 3 1 - 3 ...

  7. Android实现静默安装与卸载

    一般情况下,Android系统安装apk会出现一个安装界面,用户可以点击确定或者取消来进行apk的安装. 但在实际的项目需求中,有一种需求,就是希望apk在后台安装(不出现安装界面的提示),这种安装方 ...

  8. uva167 - The Sultan's Successors

      题意:八皇后问题的扩展.8*8棋盘上每个格子都有一个整数,要求8个皇后所在格子的数字之后最大 解法一,回溯: 用vis数组记录 列,主对角(y-x), 副对角(y+x) 访问情况 #include ...

  9. Codeforces 427 D. Match &amp; Catch

    后缀数组.... 在两个串中唯一出现的最小公共子串 D. Match & Catch time limit per test 1 second memory limit per test 51 ...

  10. 使用adns库解析域名

    1. adns.adns-python库简介 adns库是一个可进行异步非阻塞解析域名的库,主要使用C语言编写,在linux平台下运行.使用adns库进行域名解析效率非常,著名的开源网络爬虫larbi ...