//  CustomUITableViewController.h
// UI2_QQ折叠-UITableViewController
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface CustomUITableViewController : UITableViewController
{
int sectionState[20];//标志分区的状态
} //提供数据源
@property (nonatomic, retain)NSMutableArray *dataList; @end
//
// CustomUITableViewController.m
// UI2_QQ折叠-UITableViewController
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "CustomUITableViewController.h" #define FoldImageName @"arrow_fold"
#define SpreadImageName @"arrow_spread" @interface CustomUITableViewController () @end @implementation CustomUITableViewController - (instancetype)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
self.title = @"QQ折叠";
self.dataList = [NSMutableArray array];
}
return self;
} - (void)creatData
{
for (int i=0; i<20; i++) {
NSMutableArray *array = [NSMutableArray array];
for (int j=0; j<5; j++) {
NSString *name = [NSString stringWithFormat:@"小明%d", j+1];
[array addObject:name];
}
[_dataList addObject:array];
}
}
//设置分区的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.dataList.count;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//根据分区的状态返回行数
if (sectionState[section]) {
return 0;
}
return [[self.dataList objectAtIndex:section] count];
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [[self.dataList objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; return cell;
} //设置分区头视图 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectZero];
headerView.backgroundColor = [UIColor lightGrayColor];
UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 43, self.view.frame.size.width, 3)];
lineLabel.backgroundColor = [UIColor grayColor];
[headerView addSubview:lineLabel]; //加载图片
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 32, 32)];
if (sectionState[section]) {//收起的状态
imageView.image = [UIImage imageNamed:FoldImageName];
}
else
{
imageView.image = [UIImage imageNamed:SpreadImageName];
}
[headerView addSubview:imageView]; //添加点击手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
headerView.userInteractionEnabled = YES;
[headerView addGestureRecognizer:tap];
//tag值
headerView.tag = section; return headerView;
}
//0000 0000 ==0
//0000 0001 ^
//-----------
//0000 0001 ==1 //0000 0001 ==1
//0000 0001 ^
//-----------
//0000 0000 ==0 - (void)tapClick:(UITapGestureRecognizer *)tap
{
NSLog(@"-------");
NSInteger index = tap.view.tag;
sectionState[index] ^=1;
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:index] withRowAnimation:UITableViewRowAnimationFade];
} - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 46;
} - (void)viewDidLoad {
[super viewDidLoad];
[self creatData];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//  AppDelegate.m
// UI2_QQ折叠-UITableViewController
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "CustomUITableViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
CustomUITableViewController *root = [[CustomUITableViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:root];
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor]; return YES;
}

UI2_QQ折叠-UITableViewController的更多相关文章

  1. iOS - UITableViewController

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITableView : UIScrollView <NSCoding> @available(iOS ...

  2. [Swift通天遁地]九、拔剑吧-(17)创建一个三维折叠样式的页面展开效果

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. iOS UITableView 与 UITableViewController

    很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...

  4. margin折叠-从子元素margin-top影响父元素引出的问题

    正在做一个手机端电商项目,顶部导航栈的布局是一个div包含一个子div,如果给在正常文档流中的子div一个垂直margin-top,神奇的现象出现了,两父子元素的边距没变,但父div跟着一起往下走了! ...

  5. CSS3与页面布局学习总结(二)——Box Model、边距折叠、内联与块标签、CSSReset

    一.盒子模型(Box Model) 盒子模型也有人称为框模型,HTML中的多数元素都会在浏览器中生成一个矩形的区域,每个区域包含四个组成部分,从外向内依次是:外边距(Margin).边框(Border ...

  6. SSRS 实用技巧 ---- 为表格添加展开/折叠操作(明细报表)

    相信很多人都会遇到这样的需求:当表格按照某几个列分组时,需要为组添加展开和折叠的操作. 最初展现表格的时候只展现最外层分组,然后点击展开后可以查看分组内的明细情况. 先来一张效果图,然后再看具体如何实 ...

  7. [Tool] 插入折叠区域功能

    之前写了一个 仿博客园网页端推荐的插入代码插件, 后来在总结一些技术文档时,总是想把一些属性或者方法,参数等,都用表格的形式清晰的列举出来,但是插入的表格太大的话,上下跨度就显得特别大,来回上下滚动的 ...

  8. jquery隐藏侧边栏和折叠侧边栏方法

    两种效果如下所示: 隐藏侧边栏: 折叠侧边栏: 下面,分享隐藏侧边栏实现方法: 实现思路:给body切换class,通过class控制侧边栏和主体部分left 来实现效果 html部分: <di ...

  9. amazeui折叠面板智能化展开

    2016年12月12日 21:05:18 星期一 场景: 我拿这个组件用作管理后台的侧边栏 效果: 根据当前访问的url不同, 展开不同的面板 amazeui折叠面板 js代码: <script ...

随机推荐

  1. C#基础-Func,Action

    Func,Action 的介绍及其用法 Func是一种委托,这是在3.5里面新增的,2.0里面我们使用委托是用Delegate,Func位于System.Core命名空间下,使用委托可以提升效率,例如 ...

  2. Swift用UIBezierPath来画圆角矩形、自定义多路径图形

    最好的特点就是可以自定义路径,设置圆角和描边都很方便,以下为代码和效果,均在playground中实现 1.首先实现一个圆角矩形,并对此路径描边,为其绘制一个轮廓. 1 2 3 4 5 6 7 8 9 ...

  3. Java Web目录

    1. Spring持久化 2. Spring核心之IoC——依赖注入 3. Hibernate查询语言 4. Hibernate 实体关联关系映射(转载) 5. 用MyEclipse自动生成hiber ...

  4. Python高级编程–正则表达式(习题)

    原文:http://start2join.me/python-regex-answer-20141030/ ############################################## ...

  5. what is docker

    尽管之前久闻Docker的大名了,但是天资愚钝,对其到底是个啥东西一直摸不清,最近花了一段时间整理了一下,算是整理出一点头绪来. 官网的介绍是这样的: Docker is an open platfo ...

  6. asp.net等项目编译失败的原因之不能写入

    本人遇到过一次生成mvc4项目失败,说是不能写入,后发现是权限问题,特此记录. 解决方案: 对C盘下的temp文件夹设置当前用户的写入权限即可.

  7. Find the Clones

    Find the Clones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6365   Accepted: 2375 D ...

  8. 1.4.10 Schemaless模式

    Schemaless模式 schemaless模式是一组solr功能的集合,允许用户通过简单的索引例子数据快速构建一个有效的schema,而不需要手动的编辑schema.这些solr功能都是在solr ...

  9. TextRank算法提取关键词的Java实现

    转载:码农场 » TextRank算法提取关键词的Java实现 谈起自动摘要算法,常见的并且最易实现的当属TF-IDF,但是感觉TF-IDF效果一般,不如TextRank好. TextRank是在 G ...

  10. 【阿里云产品公测】高大上的搜索服务OpenSearch,你值得拥有!

    [阿里云产品公测]高大上的搜索服务OpenSearch,你值得拥有! 作者:阿里云用户trcher ​ 一.前言: 在OpenSearch没出来之前,就一直想给网站做个搜索功能,虽然网站本身自带搜索功 ...