//直接代码 只包含 折叠展开字典的处理搭建

#import "CFViewController.h"

@interface CFViewController ()<UITableViewDelegate,UITableViewDataSource>
{
UITableView *CFTableView;
//数据
NSArray * CFOnearray;
NSMutableArray *CFArray;
NSArray *CFDetailArray;
CGFloat HeightNormal; NSArray *arrayTitle;//
NSArray * arraymodeltext;//内部分组Title
CGFloat height0;//返回的高度 //按钮的状态相关
NSMutableDictionary * stateDict;//保存状态字典 }
@end
//chufang
@implementation CFViewController - (void)viewDidLoad {
[super viewDidLoad]; [self SetCustomBarWithLeftImage:@"ic_return" leftBtnString:nil titleText:@"处方" rightImageName:nil rightBtnSring:nil target:self]; [self loadData]; } -(void)loadData{ HeightNormal = IPHONEHIGHT();
CFArray = [NSMutableArray array]; //包含状态的字典。 值为1 是展开状态 0收缩,,,以section为键
stateDict = [[NSMutableDictionary alloc]init];
arrayTitle = @[@"号: ",@"添加时间: ",@"诊: ",@"明细: ",@"金额: ",@"开: "]; [[GetUrlSession shareUrlconnection]connetion:[NSString stringWithFormat:@"%@?org_code=%@&clinic_id=%@",CFUrlStr,_jzmodel.org_code,_jzmodel.clinic_id] Haget:^(NSDictionary *data, NSError *error, NSHTTPURLResponse *response) { //CFOnearray 时下载的数据。如果为空了。就不搭建UI if (CFOnearray.count>) { dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES]; [self creatUI]; }); }else{ dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES]; [self CreatNilUI]; });
} }]; } -(void)creatUI{ //创建tableView
} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return CFOnearray.count;
} //每一组 返回的行数。通过判断字典进行 看是否要展开
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ NSString * sectionNum = [NSString stringWithFormat:@"%ld",section]; NSString* state = [stateDict objectForKey:sectionNum]; if ([state isEqualToString:@""]) { return ; }else{ return ;
} }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ return cell;
}
//在透视图上添加一个button。进行监听点击事件
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIButton *backView = [[UIButton alloc]initWithFrame:CGRectMake(, , ScreenWidth, IPHONEHIGHT())]; CFModel * model = CFOnearray[section]; backView.tag = +section;
[backView addTarget: self action:@selector(tapDown:) forControlEvents:UIControlEventTouchUpInside];
backView.backgroundColor = [UIColor whiteColor]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(IPHONEWIDTH(), IPHONEHIGHT(),ScreenWidth- IPHONEWIDTH(), IPHONEHIGHT())]; label.font = [UIFont systemFontOfSize:IPHONEWIDTH()];
label.textColor = shense; //组头大名字设定
label.text = [NSString stringWithFormat:@"%@(%@)",model.diagnosis,dateSring];
[backView addSubview:label]; UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(IPHONEWIDTH(), IPHONEHIGHT(), IPHONEWIDTH(), IPHONEHIGHT())];
btn.tag = +section; /////////////////////////判断是否展开折叠 改变button的状态
NSString * sectionNum = [NSString stringWithFormat:@"%ld",section]; NSString* state = [stateDict objectForKey:sectionNum]; if ([state isEqualToString:@""]) { btn.selected = YES; }else{ btn.selected = NO; } [btn setImage:[UIImage imageNamed:@"ic_home_hospital_close"] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:@"ic_home_hospital_open"] forState:UIControlStateSelected];
[backView addSubview:btn];
//线
UIView *grayView = [[UIView alloc]initWithFrame:CGRectMake(, backView.bottom-, ScreenWidth, )];
grayView.backgroundColor = [UIColor colorWithHexString:@"f2f2f2"];
[backView addSubview:grayView];
return backView ;
}
//触发方法 改变字典的值
-(void)tapDown:(UIButton *)sender{ NSString * section = [NSString stringWithFormat:@"%ld",sender.tag-]; NSString* state = [stateDict objectForKey:section]; if ([state isEqualToString:@""]) { state = @"";
[stateDict setObject:state forKey:section]; }else{ state = @"";
[stateDict setObject:state forKey:section]; } [CFTableView reloadData]; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return IPHONEHIGHT();
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return ;
} //cell线到左边
-(void)viewDidLayoutSubviews { if ([CFTableView respondsToSelector:@selector(setSeparatorInset:)]) {
[CFTableView setSeparatorInset:UIEdgeInsetsZero]; }
if ([CFTableView respondsToSelector:@selector(setLayoutMargins:)]) {
[CFTableView setLayoutMargins:UIEdgeInsetsZero];
} }
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsZero];
}
} -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end

iOS实现类似QQ的好友列表,自由展开折叠(在原来TableView的基础上添加一个字典,一个Button)的更多相关文章

  1. web qq 获取好友列表hash算法

    web qq 获取好友列表hash算法 在使用web qq的接口进行好友列表获取的时候,需要post一个参数:hash 在对其js文件进行分析之后,发现计算hash的函数位于: http://0.we ...

  2. XMPP通讯开发-仿QQ显示好友列表和用户组

    在 XMPP通讯开发-服务器好友获取以及监听状态变化   中我们获取服务器上的用户好友信息,然后结合XMPP通讯开发-好友获取界面设计    我们将两个合并起来,首先获取用户组,然后把用户组用List ...

  3. (二十八)QQ好友列表的展开收缩

    要通过监听HeaderView上面的Button来进行操作: 通过addTarget方法即可,应该将按钮的点击方法封装在HearView控制器内部. 列表收起来的原理: tableView: numb ...

  4. qq面板/ 好友列表

    效果如下:依次为图一---图二----图三----图四 主要实现效果: 点击主标题显示下拉好友,再点击收起下拉好友:鼠标移到好友上背景颜色改变:选中的好友背景颜色也要改变: 代码如下: <!DO ...

  5. iOS 实现类似QQ分组样式的几种方式

    思路 思路很简单,对模型数据操作或则控制界面显示 先看下json部分数据 "chapterDtoList": [{ "token": null, "i ...

  6. iOS tableview自定义cell上添加按钮实现删除功能

    在删除的时候,先删除数据源,再删除cell 但是,会发现一直崩: numberOfRowsInSection 解决方案:

  7. ExpandableListView仿QQ好友列表

    本例中,对ExpandableListView中的数据进行了封装,分为两个JavaBean,一个为Group类表示组信息,一个Child类表示该组下子列表信息: Group: public class ...

  8. (二十七)QQ好友列表的实现

    QQ好友列表通过plist读取,plist的结构为一组字典,每个字典内有本组的信息和另外一组字典代表好友. 要读取plist,选择合适的数据结构,例如NSArray,然后调用initWithConte ...

  9. 基于Qt的相似QQ好友列表抽屉效果的实现

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/shuideyidi/article/details/30619167     前段时间在忙毕业设计, ...

随机推荐

  1. mysql 查询数据库内各表的占用大小

    select TABLE_NAME, concat(truncate(data_length/1024/1024,2),' MB') as data_size, concat(truncate(ind ...

  2. Ambari概览

    文章作者:luxianghao 文章来源:http://www.cnblogs.com/luxianghao/p/7886195.html  转载请注明,谢谢合作. 免责声明:文章内容仅代表个人观点, ...

  3. Android OpenGL ES 开发(二): OpenGL ES 环境搭建

    零:环境搭建目的 为了在Android应用程序中使用OpenGL ES绘制图形,必须要为他们创建一个视图容器.其中最直接或者最常用的方式就是实现一个GLSurfaceView和一个GLSurfaceV ...

  4. 初识分布式计算:从MapReduce到Yarn&Fuxi

      这些年,云计算.大数据的发展如火如荼,从早期的以MapReduce为代表的基于文件系统的离线数据计算,到以Spark为代表的内存计算,以及以Storm为代表的实时计算,还有图计算等等.只要数据规模 ...

  5. 在Linux中使用线程

    我并不假定你会使用Linux的线程,所以在这里就简单的介绍一下.如果你之前有过多线程方面的编程经验,完全可以忽略本文的内容,因为它非常的初级. 首先说明一下,在Linux编写多线程程序需要包含头文件p ...

  6. php简单实现发微博动态

    首先,肯定是注册成为开发者新浪微博开放平台 选择网站应用,填写一些基本信息 填完后在'我的应用'中,会看到刚创建的应用信息,我们只是简单的测试一下,所以其他复杂的注册信息都不用填写,有这些就够了 很重 ...

  7. PHP基础 windows环境下安装Apache Mysql PHP

    本篇文章主要是讲一下我自己安装wamp环境的一些步骤和见解,前方多图预警,慎入!!!!! PHP运行环境  : Linux下的三种安装方式:源码包安装.rpm包安装.集成环境安装(lnmp) wind ...

  8. ibv_open_device()函数

    struct ibv_context *ibv_open_device(struct ibv_device *device); 描述 函数会创建一个RDMA设备相关的context:可以通过ibv_c ...

  9. 数据结构与算法(C/C++版)【树与二叉树】

    第六章<树与二叉树> 树结构是一种非线性存储结构,存储的是具有"一对多"关系的数据元素的集合. 结点: A.B.C等,结点不仅包含数据元素,而且包含指向子树的分支.例如 ...

  10. 二叉排序树(BST)构造与应用

             二叉排序树(BST)构造与应用       本文取自<数据结构与算法>(C语言版)(第三版).出版社是清华大学出版社.       本博文作为学习资料整理. 源码是VC+ ...