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 前段时间在忙毕业设计, ...
随机推荐
- Python第一天自学,变量,基本数据类型
PyCharm 一些简单常用设置操作设置模板 File->Settings->Editor->File and Code Templates //切换python版本File-> ...
- Logger.getLogger和 LogFactory.getLog
Logger.getLogger和 LogFactory.getLog Logger.getLogger LogFactory.getLogLogger来自log4j自己的包.如果用Logger.ge ...
- 关于String中的不变模式
不变模式 不变模式就是为了尽可能的去除并行中的同步操作,提高并行程序的性能,可以使用一种不可改变的对象,依靠对象的不变性,可以确保其在没有同步操作的多线程环境中依然始终保持内部状态的一致性和正确性.并 ...
- 企业级监控zabbix基础
一个标准的监控系统所具备的基本功能: 1.数据的采集 2.为了展示其长期走势,将数据存储下来 3.万一某次采样的结果不在被认为是合理的范围内,然后就会做出告警操作,尽早的让相关人员得知到此消息 4.展 ...
- 分布式监控系统Zabbix3.2给异常添加邮件报警
在前一篇 分布式监控系统Zabbix3.2跳坑指南 中已安装好服务端和客户端,此处客户端是被监控的服务器,可能有上百台服务器.监控的目的一个是可以查看历史状态,可以对比零晨和工作区间数据的对比,以便后 ...
- python 正则空格\xa0实录 与xpath取 div 里面的含多个标签的所有文字
业余玩爬虫时,由原先的原生写法 改为 scrapy框架了,使用自带的selector时,xpath配合正则来抓取回复数和阅读数的时候,遇到的小问题,mark下. 首先获取到 我需要的数据块,(我用sc ...
- 制作支持 BIOS+UEFI 的 U 盘 grub2+bootmgr 引导 + deepin_recovery + deepin_iso + win_pe
网盘下载:https://pan.baidu.com/s/1c2GXPo0 U盘为 FAT32,MBR分区表 1.下载:U盘grub2+bootmgr引导2017.12.6.2.7z 2.解压到 U盘 ...
- PHP的AES加密类
PHP的AES加密类 aes.php <?php /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ...
- System.getProperty()方法获取系统变量
来自我的CSDN博客 今天在阅读JDBC的DriverManager类源码时,看到了这么一句代码: System.getProperty("jdbc.drivers"): ...
- Java-----关于eclipse导入项目发生的问题及解决办法
今天通过eclipse导入了几个项目,项目名出现红叉,对于我这样的强迫症来说是无法容忍的,故现做总结,遇到同学可按照以下方法来操作. 改动的地方主要是两个方面: 1.Tomcat版本问题. 此问题是由 ...