UI2_QQ折叠-UITableViewController
// 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的更多相关文章
- iOS - UITableViewController
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITableView : UIScrollView <NSCoding> @available(iOS ...
- [Swift通天遁地]九、拔剑吧-(17)创建一个三维折叠样式的页面展开效果
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- iOS UITableView 与 UITableViewController
很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...
- margin折叠-从子元素margin-top影响父元素引出的问题
正在做一个手机端电商项目,顶部导航栈的布局是一个div包含一个子div,如果给在正常文档流中的子div一个垂直margin-top,神奇的现象出现了,两父子元素的边距没变,但父div跟着一起往下走了! ...
- CSS3与页面布局学习总结(二)——Box Model、边距折叠、内联与块标签、CSSReset
一.盒子模型(Box Model) 盒子模型也有人称为框模型,HTML中的多数元素都会在浏览器中生成一个矩形的区域,每个区域包含四个组成部分,从外向内依次是:外边距(Margin).边框(Border ...
- SSRS 实用技巧 ---- 为表格添加展开/折叠操作(明细报表)
相信很多人都会遇到这样的需求:当表格按照某几个列分组时,需要为组添加展开和折叠的操作. 最初展现表格的时候只展现最外层分组,然后点击展开后可以查看分组内的明细情况. 先来一张效果图,然后再看具体如何实 ...
- [Tool] 插入折叠区域功能
之前写了一个 仿博客园网页端推荐的插入代码插件, 后来在总结一些技术文档时,总是想把一些属性或者方法,参数等,都用表格的形式清晰的列举出来,但是插入的表格太大的话,上下跨度就显得特别大,来回上下滚动的 ...
- jquery隐藏侧边栏和折叠侧边栏方法
两种效果如下所示: 隐藏侧边栏: 折叠侧边栏: 下面,分享隐藏侧边栏实现方法: 实现思路:给body切换class,通过class控制侧边栏和主体部分left 来实现效果 html部分: <di ...
- amazeui折叠面板智能化展开
2016年12月12日 21:05:18 星期一 场景: 我拿这个组件用作管理后台的侧边栏 效果: 根据当前访问的url不同, 展开不同的面板 amazeui折叠面板 js代码: <script ...
随机推荐
- Android 图像压缩,和LRU算法使用的推荐链接
近两日,看的关于这些方面的一些教程数十篇,最好的当属google原版的教程了.国内有不少文章是翻译这个链接的. 需要注意的一点是:Android的SDK中的LRU算法在V4包和Util包中各有一个,推 ...
- 浏览器禁用Cookie,基于Cookie的会话跟踪机制失效的解决的方法
当浏览器禁用Cookies时.基于Cookie的会话跟踪机制就会失效.解决的方法是利用URL重写机制跟踪用户会话. 在使用URL重写机制的时候须要注意.为了保证会话跟踪的正确性,全部的链接和重定向语句 ...
- MTD NANDFLASH驱动相关知识介绍
转:http://blog.csdn.net/zhouzhuan2008/article/details/11053877 目录 MTD总概述 MTD数据结构 MTD相关层实现 MTD,Memory ...
- 解决CSDN的code功能,无法git clone多个项目的问题
几天前在使用CSDN的git功能的时候发现一个问题:我在CSDN上创建了两个项目,但是却只能git clone其中的一个. 原因: 在添加ssh公钥的时候,将主机上的ssh公钥在CSDN上填的地方不合 ...
- Linux Shell之top命令
TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系统中C ...
- 编写一个简单的Jquery插件
1.实现内容 定义一个简单的jquery插件,alert传递进来的参数 2.插件js文件(jquery.showplugin.js) (function ($) { //定义插件中的方法 var me ...
- C#基础--局部类型Partial
局部类型 原本来在同一个命名(namespace)空间下 是不允许相同的类(class)名存在的 但是partial关键字可以允许在同一个namespace下有想通过的类名存在 写法 下面的两个不 ...
- 巧用FileShare解决C#读写文件时文件正由另一进程使用的bug
在使用C#进行文件读写的时候,一旦对文件操作频繁,总会碰到一些令人措手不及的意外.例如经常会碰到的一个问题: System.IO.IOException: 文件“XXX”正由另一进程使用,因此该进程无 ...
- Uva 10596 - Morning Walk 欧拉回路基础水题 并查集实现
题目给出图,要求判断不能一遍走完所有边,也就是无向图,题目分类是分欧拉回路,但其实只要判断度数就行了. 一开始以为只要判断度数就可以了,交了一发WA了.听别人说要先判断是否是联通图,于是用并查集并一起 ...
- 重构3-Pull Up Method(方法上移)
上移方法(Pull Up Method)重构是将方法向继承链上层迁移的过程.用于一个方法被多个实现者使用时 public abstract class Vehicle { // other metho ...