iOS实现类似QQ的好友列表,自由展开折叠(在原来TableView的基础上添加一个字典,一个Button)
//直接代码 只包含 折叠展开字典的处理搭建 #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)的更多相关文章
- web qq 获取好友列表hash算法
web qq 获取好友列表hash算法 在使用web qq的接口进行好友列表获取的时候,需要post一个参数:hash 在对其js文件进行分析之后,发现计算hash的函数位于: http://0.we ...
- XMPP通讯开发-仿QQ显示好友列表和用户组
在 XMPP通讯开发-服务器好友获取以及监听状态变化 中我们获取服务器上的用户好友信息,然后结合XMPP通讯开发-好友获取界面设计 我们将两个合并起来,首先获取用户组,然后把用户组用List ...
- (二十八)QQ好友列表的展开收缩
要通过监听HeaderView上面的Button来进行操作: 通过addTarget方法即可,应该将按钮的点击方法封装在HearView控制器内部. 列表收起来的原理: tableView: numb ...
- qq面板/ 好友列表
效果如下:依次为图一---图二----图三----图四 主要实现效果: 点击主标题显示下拉好友,再点击收起下拉好友:鼠标移到好友上背景颜色改变:选中的好友背景颜色也要改变: 代码如下: <!DO ...
- iOS 实现类似QQ分组样式的几种方式
思路 思路很简单,对模型数据操作或则控制界面显示 先看下json部分数据 "chapterDtoList": [{ "token": null, "i ...
- iOS tableview自定义cell上添加按钮实现删除功能
在删除的时候,先删除数据源,再删除cell 但是,会发现一直崩: numberOfRowsInSection 解决方案:
- ExpandableListView仿QQ好友列表
本例中,对ExpandableListView中的数据进行了封装,分为两个JavaBean,一个为Group类表示组信息,一个Child类表示该组下子列表信息: Group: public class ...
- (二十七)QQ好友列表的实现
QQ好友列表通过plist读取,plist的结构为一组字典,每个字典内有本组的信息和另外一组字典代表好友. 要读取plist,选择合适的数据结构,例如NSArray,然后调用initWithConte ...
- 基于Qt的相似QQ好友列表抽屉效果的实现
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/shuideyidi/article/details/30619167 前段时间在忙毕业设计, ...
随机推荐
- shopxx------list列表回显修改尝试
需求:在商品列表展示页面增加一列 一.修改模板 1.列表页面对应的freemarker模板位置 /shopxx/WebContent/WEB-INF/template/admin/product/li ...
- virtualbox下centos实现主宿互访
1.网络连接方式 NAT 桥接 Host-Only NAT: 网络地址转换,virtualbox默认采用这种连接方式,特点: 1.虚拟机配置稍作修改就能连上外网 2.虚拟机可以ping通主机,主机不能 ...
- unity中.meta提交错误操作导致空脚本
工作时遇到了一个奇葩的问题,同事做的界面,再策划那里死活无法运行,其他同事的都没有问题.简单一查,是界面上挂了个空脚本,但是同事提交了对应的脚本,其他人那里脚本是正常.随后想到是否是.meta的问题. ...
- XSD详解二 - 简易元素、属性、内容限定
一.XSD 简易元素 XML Schema 可定义 XML 文件的元素. 简易元素指那些只包含文本的元素.它不会包含任何其他的元素或属性. 1.什么是简易元素? 简易元素指那些仅包含文本的元素.它不会 ...
- php获取当前月与上个月月初及月末时间戳的方法
php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime.下面首先还是直奔主题以示例说明如何使用 mktime 获取今日.昨日.上周.本月的起始 ...
- ##1.Centos7环境准备-- openstack pike
##1.Centos7环境准备 openstack pike 安装 目录汇总 http://www.cnblogs.com/elvi/p/7613861.html ##.Centos7环境准备 #Ce ...
- Jackson将json string转为Object,org.json读取json数组
从json文件读取json string或者自定义json string,将其转为object.下面采用的object为map,根据map读取json的某个数据,可以读取第一级的数据name,后来发现 ...
- PAT 1042. Shuffling Machine (20)
1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shu ...
- SQL Server学习之路(二):主键和外键
0.目录 1.定义 1.1 什么是主键和外键 1.2 主键和外键的作用 1.3 主键.外键和索引的区别 2.主键(primary key) 2.1 通过SSMS设置主键 2.2 通过SQL语句设置主键 ...
- 深入研究-webkit-overflow-scrolling:touch及ios滚动
1. -webkit-overflow-scrolling:touch是什么? MDN上是这样定义的: -webkit-overflow-scrolling 属性控制元素在移动设备上是否使用滚动回弹效 ...