//

//  LHQReportOnTheUseOfFundsCtrl.m

//  11 - 投资管理 - 李洪强

//  资金使用情况汇报

//  Created by vic fan on 16/4/12.

//  Copyright © 2016年 李洪强. All rights reserved.

//

#define SCREENW [UIScreen mainScreen].bounds.size.width

#define SCREENH [UIScreen mainScreen].bounds.size.height

#import "LHQReportOnTheUseOfFundsCtrl.h"

#import "LHQContentViewCell.h"

#import "LHQDelegateModel.h"

#import "NSString+Frame.h"

#import "LHQCustomHeader.h"

@interface LHQReportOnTheUseOfFundsCtrl ()<UITextViewDelegate>

@property(nonatomic)NSMutableArray *dataArr;

//记录所有分组的折叠状态

@property(nonatomic)NSMutableArray *closeArr;

@end

@implementation LHQReportOnTheUseOfFundsCtrl

- (void)viewDidLoad {

[super viewDidLoad];

self.title = @"资金使用情况汇报";

[self.tableView registerNib:[UINib nibWithNibName:@"LHQContentViewCell" bundle:nil] forCellReuseIdentifier:@"LHQContentViewCell"];

[self createData];

}

-(void)viewWillDisappear:(BOOL)animated

{

_dataArr = nil;

_closeArr = nil;

}

//数据

- (void)createData{

NSArray *tmpArray = @[@"2015年11月资金情况汇报",@"2015年10月资金情况汇报",@"2015年9月资金情况汇报",@"2015年8月资金情况汇报",@"2015年7月资金情况汇报",@"2015年6月资金情况汇报"];

//循环给标题赋值

for (int i=0; i<6; i++) {

LHQDelegateModel *model = [[LHQDelegateModel alloc] init];

model.titleName = tmpArray[i];

//循环给每一个cell里面的数据数组赋值

for (int j=0; j<4; j++) {

[model.contentArr addObject:@"13bcbduaib"];

}

//把模型model放到数据数组中

[self.dataArr addObject:model];

[self.closeArr addObject:[NSNumber numberWithBool:YES]];

}

[self.tableView reloadData];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

#pragma mark - Table view data source

//几组

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return _dataArr.count;

}

//几行

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

//如果是关闭状态

//objectAtIndex:(NSUInteger)index : 获取数组中索引为index的元素

if ([[_closeArr objectAtIndex:section] boolValue]) {

return 0;

}

// 如果是打开的状态--> 返回每一组只有一行

return 1;

}

//每一行显示的内容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

LHQContentViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LHQContentViewCell" forIndexPath:indexPath];

if (!cell) {

cell=[[LHQContentViewCell alloc] init];

}

LHQDelegateModel *model = _dataArr[indexPath.section];

[cell customedWithModel:model];

// cell.backgroundColor = [UIColor blueColor];

return cell;

}

//每一行的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 223;

}

//定义段头

//头部高度

-(CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

return 60;

}

//头部视图

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{   //用btn当作段头的view

LHQDelegateModel *model = _dataArr[section];

LHQCustomHeader *headerView = [[[NSBundle mainBundle] loadNibNamed:@"LHQCustomHeader" owner:self options:nil] firstObject];

//定义一个变量是打开的状态

//indexOfObject 对象是否存在数组中,如果存在返回对象所在的下标

NSInteger numx = [self.closeArr indexOfObject:[NSNumber numberWithBool:0]];

//如果组是打开的状态

if (numx == section) {

//设置箭头为向上的

[headerView setImageWithName:@"Snip20160413_9"];

}else{

//否则还是原来的

[headerView setImageWithName:@"Snip20160413_8"];

}

//给headView绑定tag值

headerView.tag = section + 400;

//给标题赋值

headerView.titleLable.text = model.titleName;

UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnClick:)];

[headerView addGestureRecognizer:tapGR];

CALayer *layer = [headerView layer];

[layer setMasksToBounds:YES];//设置边框可见

layer.borderColor = [[UIColor lightGrayColor] CGColor];

[layer setBorderWidth:0.5];

//Border: 边境

return headerView;

}

//点击选择

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

// [self.delegate  sendLocation:[_dataArr[indexPath.section] objectAtIndex:indexPath.row]];

// [self dismissViewControllerAnimated:YES completion:nil];

}

//点击头部

-(void)btnClick:(UITapGestureRecognizer *)tapGR

{

//找到对应的折叠状态

//此时是关闭状态

BOOL isClose = [[_closeArr objectAtIndex:tapGR.view.tag-400] boolValue];

//(要点: 点击某一行cell,如果当前cell的状态是关闭的,点击的时候就把当前的cell切换到打开的状态,同时把其他所有的cell的状态都关闭

// 如果当前的cell状态是打开的,点击的时候,把所有的状态改成关闭状态)

//-----------------------------------------------------------

for (int i=0; i<6; i++) {

//如果点击的tag值在范围之内

if (i == tapGR.view.tag - 400) {

//当前点击的cell的索引正好是关闭的那个状态,什么都不做

//如果打开的是当前的某一个cell,什么都不做

//如果是其他的,让其他的关闭

}else{

//没打开的状态

[self.closeArr replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:YES]];

}

}

//----------------------------------------------------------

//修改折叠状态

//把关闭的那个索引的cell变成打开的状态

[_closeArr replaceObjectAtIndex:tapGR.view.tag-400 withObject:[NSNumber numberWithBool:!isClose]];

[self.tableView reloadData];

}

#pragma mark - textView的代理方法

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {

NSLog(@"url :%@",URL);

NSLog(@"111");

if ([[URL scheme] isEqualToString:@"username"]) {

NSString *username = [URL host];

NSLog(@"username :%@",username);

return NO;

}

return YES;

}

#pragma mark - 懒加载

-(NSMutableArray *)dataArr

{

if (!_dataArr) {

_dataArr = [[NSMutableArray alloc] init];

}

return _dataArr;

}

-(NSMutableArray *)closeArr

{

if (!_closeArr) {

_closeArr = [[NSMutableArray alloc] init];

}

return _closeArr;

}

@end

tableviewCell折叠状态1的更多相关文章

  1. tableviewCell折叠状态3

    // //  LHQDelegateModel.h //  11 - 投资管理 - 李洪强 // //  Created by vic fan on 16/4/13. //  Copyright © ...

  2. tableviewCell折叠状态2

    // //  LHQContentViewCell.h //  11 - 投资管理 - 李洪强 // //  Created by vic fan on 16/4/12. //  Copyright ...

  3. vim设置为indent折叠以后,每次打开文件时代码处于折叠状态,能改变吗?

    vim设置为indent折叠以后,每次打开文件时代码处于折叠状态.即使这次编辑的时候把折叠展开,保存关闭文件,重新打开,所有的代码都又折叠起来了. 请问有没有默认不折叠的方法? 是否有可以一次展开所有 ...

  4. 取消TableViewCell选中状态的外观变化

    tabelViewcell 使用Xib创建自定义外观的时候,在tableview选中的时候,cell的外观会发生变化,在定义Xib中如下图将选中的外观状态取消掉 也有其他选项,可以选择控制选中的时候的 ...

  5. tableviewcell折叠问题,(类似qq列表展开形式) 多个cell同时展开,OC版 和 Swift

    之前没有用到过这块,但是今天看到,就试了试,但是发现,网上的有的方法不能多个cell同时展开,只能一个一个的展开. 我就尝试用用数组记录展开的标记的方法,功能实现了, 直接上代码: // // Vie ...

  6. iOS中 UITableViewRowAction tableViewcell编辑状态下的功能 UI技术分享

    * tableView:editActionsForRowAtIndexPath: // 设置滑动删除时显示多个按钮 * UITableViewRowAction // 通过此类创建按钮 * 1. 我 ...

  7. tableviewcell的这贴状态和传值总结

    01  控制器 1.1 定义一个可变数组存放数据,再定义一个可变数组来记录分组的折叠状态 @property(nonatomic)NSMutableArray *dataArr; //记录所有分组的折 ...

  8. jquery ztree 刷新后记录折叠、展开状态

    ztree :http://www.ztree.me/v3/main.php 项目中用到了这个插件,刚好也有需求 在页面刷新后,保存开始的展开.折叠状态, 其实 dtree: http://www.d ...

  9. listview嵌套gridview,并实现grid元素部分显示以及点击展开与折叠

    原文链接:http://blog.csdn.net/duguju/article/details/49538341 有时我们需要用GridView显示目录列表,有时甚至是二级的,即listview每一 ...

随机推荐

  1. 面向侧面的程序设计AOP-------《三》.Net平台AOP技术概览

    本文转载自张逸:晴窗笔记 .Net平台与Java平台相比,由于它至今在服务端仍不具备与unix系统的兼容性,也不具备类似于Java平台下J2EE这样的企业级容器,使得.Net平台在大型的企业级应用上, ...

  2. iOS7上在xib中使用UITableViewController设置背景色bug

    今天用xcode5.1设置xib中,用静态的方式设置UITableViewController中的tableview,把tableview中的backgroundColor改变后,xib上有效果,但是 ...

  3. canvas API ,通俗的canvas基础知识(三)

    全文说到了三角形,圆形等相关图形的画法,不熟悉的同学可以出门右转,先看看前文,接下来继续我们的图形——曲线. 学过数学,或者是比较了解js 的同学都知道贝塞尔曲线,当然,在数学里面,这是一门高深的学问 ...

  4. Ubuntu的一些常用快捷键

    Ubuntu操作基本快捷键 * 打开主菜单 = Alt + F1 * 运行 = Alt + F2 * 显示桌面 = Ctrl + Alt + d * 最小化当前窗口 = Alt + F9 * 最大化当 ...

  5. 针对不同包之间的action跳转,怎么配置?

    例如一下的例子:两个包,如何跳转 <struts>           <constant name="struts.enable.DynamicMethodInvocat ...

  6. 使用show profiles分析SQL性能

    如何查看执行SQL的耗时 使用show profiles分析sql性能. Show profiles是5.0.37之后添加的,要想使用此功能,要确保版本在5.0.37之后. 查看数据库版本 mysql ...

  7. Web服务器原理及简单实现

    Web系统由客户端(浏览器)和服务器端两部分组成.Web系统架构也被称为B/S架构.最常见的Web服务器有Apache.IIS等,常用的浏览器有IE.Firefox.chrome等.当你想访问一个网页 ...

  8. OpenStack Swift集群与Keystone的整合使用说明

    之前已经介绍了OpenStack Swift集群和Keystone的安装部署,最后来讲一讲Swift集群与Keystone的整合使用吧. 1. 简介 本文档描述了Keystone与Swift集群的整合 ...

  9. html 表单 dom 注意跟表单的name值一致

    html 表单 dom 注意跟表单的name值一致 <script type="text/javascript"> function checkForm() { var ...

  10. Linux 串口编程(转)

    无论那种操作方式,一般都通过四个步骤来完成: (1) 打开串口 (2) 配置串口 (3) 读写串口 (4) 关闭串口 转自