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 ...
随机推荐
- UVA1099----Sharing Chocolate----在集合上的DP
题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 1028 - Carl the Ant
Ants leave small chemical trails on the ground in order to mark paths for other ants to follow. Ordi ...
- 线性表 及Java实现 顺序表、链表、栈、队列
数据结构与算法是程序设计的两大基础,大型的IT企业面试时也会出数据结构和算法的题目, 它可以说明你是否有良好的逻辑思维,如果你具备良好的逻辑思维,即使技术存在某些缺陷,面试公司也会认为你很有培养价值, ...
- 《嵌入式Linux基础教程》补充阅读建议电子数目下载
第二章 <Linux内核设计与实现(原书第三版)> <深入理解Linux内核(第三版)> <深入理解Linux虚拟内存管理> 其他与Linux相关的电子书下载地址: ...
- Booting ARM Linux
来源:linux-2.6.30.4/Documentation/arm/Booting ARM Linux Booting ARM Linux ================= ...
- 代码片段---判断一文件是不是字符设备如果是把它拷贝到 /dev目录下
#!/bin/sh myfile=/home/liu 这个是文件的路径 fd = `ls -l myfile` 获取文件的所有属性 fp= ${fd::} if ["$fp" = ...
- A SQLite client library written in Modern C++
smartdb是一个纯c++11开发,header-only,简洁高效的sqlite封装库. github地址:https://github.com/chxuan/smartdb,如果您觉得不错,请不 ...
- LeetCode31 Next Permutation
题目: Implement next permutation, which rearranges numbers into the lexicographically next greater per ...
- Play on Words 欧拉通路(回路)判断
Play on Words note: 判断一下连通性. #include <iostream> #include <cstdio> #include <cstring ...
- MySQL(21):事务管理之 事务提交
1. 现实生活中,许多操作都是需要用户确认的,例如用户删除一个文档,删除时候会弹出一个提示对话框,包含"确认"和"取消".同样的道理,在数据库中有些命令在使用的 ...