//  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. 排版系统Latex傻瓜方式使用(论文排版)

    0. 什么是Latex? LaTEX(英语发音:/ˈleɪtɛk/ lay-tek或英语发音:/ˈlɑːtɛk/ lah-tek,音译"拉泰赫").文字形式写作LaTeX.是一种基 ...

  2. 怎样基于android4.4.2的源代码和android-4.3.1_r1的驱动编译I9250的ROM

    怎样基于android4.4.2的源代码和android-4.3.1_r1的驱动编译I9250的ROM 作者:雨水  2014-05-04 联系方式:dennis.hu.cd at gmail.com ...

  3. 浏览器中打开IOS应用并传参

    原创文章,转载请注明 开发中遇到这么一个问题,就是动态地指定联接服务器地址,或其它数据.如果是其它数据还好说一些,可以通过在服务器上获得的方式来弄.但如果服务器地址都需要动态指定的话.那就得另想办法了 ...

  4. C#开源项目

    原文:  http://alance.iteye.com/blog/693987 一.AOP框架        Encase 是C#编写开发的为.NET平台提供的AOP框架.Encase 独特的提供了 ...

  5. [022]c++虚函数、多态性与虚表

    原文出处:http://my.oschina.net/hnuweiwei/blog/280894 目录[-] 多态 虚函数 纯虚函数 虚表 一般继承(无虚函数覆盖) 一般继承(有虚函数覆盖) 多重继承 ...

  6. EF 预热

    由于EF第一次加载比较慢,所以要对EF进行一次初始化的加载,类似第一次打开网页很慢,但第二次打开都很快了的原理一样:第一次把所有静态的图片和JS缓存到本地了:当第二次打开的时候都不需要再去下载这些东西 ...

  7. QQ群信息统计

    接口一: 1:QQ群信息统计 地址:http://localhost:8080/webServices/messageSort 注意:连接地址提交的是一个txt文件,返回是一个list的json字符串 ...

  8. The Socket API, Part 3: Concurrent Servers

    转:http://www.linuxforu.com/2011/10/socket-api-part-3-concurrent-servers/ By Pankaj Tanwar on October ...

  9. 关于在线查看相关开源源码的网站,包括Android源码

    无废话,纯干货! 各种源码自行搜索: http://grepcode.com/ Android源码:http://grepcode.com/project/repository.grepcode.co ...

  10. JavaEE&Docker 容器示例

    准备:jboss.jdk.一个javaee的war包.Dockerfile 注:jboss和jdk可以不用提前准备好,在命令中wget也可以,因为我恰好有,就直接复制了 Dockerfile内容: # ...