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

#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. linux平台搭建postfix邮件服务器

    一,搭建邮件服务器前准备如下: Centos 7.2 64位Postfix-2.8.12.tar.gz Postfix MTA(邮件传输代理)Dovecot-2.1.8.tar.gz IMAP 和 P ...

  2. canvas三环加载进度条

    之前做了一个三个圆形叠加在一起的加载,用的是定位和cile来操作,但是加载的头部不能是圆形.后来用canvas做了一个,但是这个加载的进度不好调整,原理很简单,就是让一个圆,按照圆形轨迹进行运动就可以 ...

  3. centos搭建java web服务器

    1.安装jdk7 //检查jdk是否已经安装 [root@iZwz9catu2mrq92b07d1d0Z ~]# yum list installed | grep java java--openjd ...

  4. linux如何在日志中查找关键字、前几行、结尾几行

    如何使用命令行快速查看项目日志是每个开发人员必备技能,尤其在没有专门日志搜集系统的情况下,想要知道目前项目运行状态最好的办法就是打开log日志一瞅即明白. 复杂的到用时再查不晚,但是简单的还是有必要掌 ...

  5. 操作系统学习笔记----进程/线程模型----Coursera课程笔记

    操作系统学习笔记----进程/线程模型----Coursera课程笔记 进程/线程模型 0. 概述 0.1 进程模型 多道程序设计 进程的概念.进程控制块 进程状态及转换.进程队列 进程控制----进 ...

  6. JavaWeb框架SSH_Struts2_(四)----->表达式语言OGNL

    1. 表达式语言OGNL OGNL简介 OGNL基本语法 常量 操作符 OGNL表达式 OGNL基础 OGNL上下文 OGNL值栈 OGNL的访问 2. 具体内容 2.1 OGNL简介 OGNL(Ob ...

  7. MySQL的安装(比较详细的安装步骤,包括客户端和服务端的安装,还有环境变量的配置以及使用Windows service启动MySQL)

    1.MySQL官网下载操作系统对应的MySQL安装包,解压之后就可以直接使用(免安装). MySQL安装包,一种是MySQL Enterprise Edition (commercial)企业版,还有 ...

  8. 晓莲说-何不原创:java 实现二维数组冒泡排序

    新手从业路-为自己回顾知识的同时,也希望和大家分享经验: 话不多说,上代码 public class 冒泡排序 { /**     * @param admin     * @2017.12.4   ...

  9. RPC是什么

    RPC是什么? 通俗的讲就是,调用远程计算机上的服务,就像调用本地服务一样.通常包含传输协议和编码协议. RPC可以基于HTTP或TCP协议,但基于HTTP协议的RPC性能却不如基于TCP协议的RPC ...

  10. gcc & gdb & make 定义与区别

    GCC 通常所说的GCC是GUN Compiler Collection的简称,除了编译程序之外,它还含其他相关工具,所以它能把易于人类使用的高级语言编写的源代码构建成计算机能够直接执行的二进制代码. ...