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 ...
随机推荐
- 给windows 7安装文件添加USB3.0驱动
给Air安装win7进入语言与区域选择之后,发现键盘触摸板都失灵. 原因:新款的 Macbook Air 2013 因为使用了 USB3.0 端口键盘和触摸板设备,所以在安装 Windows 7 ...
- AVAST 4.8
AVAST专业版注册序列号不能用了就换一个继续注册,接着用序列号:S9665355R9665P1106-YCX4AKKT (2012.5.3)S7592769R8591F1106-ZVDJPMLT ( ...
- LRESULT与wParam和lParam的问题
在微软vc提供的头文件中有定义在winnt.h中typedef long LONG;在windef.h中typedef LONG LRESULT; 所以LRESULT就是long,也就是长整形之所以取 ...
- BeanFactory和ApplicationContext的作用和区别
BeanFactory和ApplicationContext的作用和区别 作用: 1. BeanFactory负责读取bean配置文档,管理bean的加载,实例化,维护bean之间的依赖关系,负责be ...
- 转载:页面加载swf插件:swfobject
转自:http://www.cnblogs.com/analyzer/articles/1299592.html 我一直都在用SWFObject 插入flash,好处多多,代码简洁,不会出现微软的“单 ...
- 数据库 SQL :有关 NULL 值引发 TRUE、FALSE、UNKNOW 三值逻辑
在 Java.C# 中,相信如果是 boolean 类型值,只有两种选择 true.false.然而,在 SQL 查询中,NULL 值的引入,使得新增了 UNKNOW ,因此,就产生了 TRUE.FA ...
- linux-用户建立及权限分配
1.建立用户 useradd –d /usr/test -m test 此命令创建了一个用户test,用户主目录为/usr/test 2.设置用户密码 .修改自己的密码 passwd ,需要输入旧 ...
- 常见错误:Apple Mach-O Linker Error
常见错误描述: Apple Mach-O Linker Error这类错误的错误信息最后一行通常如下: Command /Developer/Platforms/iPhoneOS.platform/D ...
- Vehicle Network Protocols -- ISO/KWP CAN CCD PCI SCI / SCP / Class 2
Vehicle Network Protocols There are 5 protocols in the OBD2 system and a car will normally only use ...
- poj3250 Bad Hair Day
Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow ...