利用tableView的分组功能进行qq页面设计
来源:互联网 发布:安卓mac修改器apk 编辑:程序博客网 时间:2024/05/16 14:12
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
//加载数据
[self_loadData];
//加载视图
[self_loadTableView];
}
#pragma mark - 加载数据
- (void)_loadData{
//获取文件所在路径--数组
NSString * path=[[NSBundlemainBundle]pathForResource:@"friends.plist"ofType:nil];
self.dataArray=[NSArrayarrayWithContentsOfFile:path];
}
#pragma mark - 加载tableView
- (void)_loadTableView{
UILabel * titleLabel=[[UILabelalloc]initWithFrame:CGRectMake(0, 20,self.view.frame.size.width, 60)];
titleLabel.text=@"QQ列表";
titleLabel.textColor=[UIColorredColor];
titleLabel.font=[UIFontboldSystemFontOfSize:30];
titleLabel.textAlignment=NSTextAlignmentCenter;
[self.viewaddSubview:titleLabel];
UITableView * tableView=[[UITableViewalloc]initWithFrame:CGRectMake(0, 80,self.view.frame.size.width,self.view.frame.size.height-80)style:UITableViewStyleGrouped];
tableView.delegate=self;
tableView.dataSource=self;
tableView.rowHeight=70;//cell的高度
tableView.sectionFooterHeight=0;//设置尾部高度为0
self.tableView=tableView;
tableView.backgroundColor=[UIColorclearColor];
[self.viewaddSubview:tableView];
}
#pragma mark - UITableViewDataSource
//返回行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//如果开关已经打开,则返回实际的数据行数
if(self.staticDic[@(section)]){
NSDictionary * temDic=self.dataArray[section];
NSArray * section=[temDic valueForKey:@"friends"];
return section.count;
}
return 0;
}
//返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString * identy=@"table";
UITableViewCell * cell=[tableViewdequeueReusableCellWithIdentifier:identy];
if(!cell){
cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:identy];
}
cell.backgroundColor=[UIColorclearColor];
NSDictionary * temDic=self.dataArray[indexPath.section];
NSArray * temArray=temDic[@"friends"];
cell.textLabel.text=temArray[indexPath.row];
cell.detailTextLabel.text=@"在线";
NSString * imageName=[NSStringstringWithFormat:@"head%i",arc4random_uniform(7)+1];
cell.imageView.image=[UIImageimageNamed:imageName];
return cell;
}
//返回分组数量
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
returnself.dataArray.count;
}
#pragma mark - UITableViewDelegate
#pragma mark - 设置头部高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 50;
}
#pragma mark - 自定义头部
//返回header
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
//为头部设置可以重复利用的view
static NSString * identy=@"headerfoot";
UITableViewHeaderFooterView * hf=[tableViewdequeueReusableHeaderFooterViewWithIdentifier:identy];
if(hf==nil){
hf=[[UITableViewHeaderFooterViewalloc]initWithReuseIdentifier:identy];
UIView * headView=[[UIViewalloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, 48)];
headView.tag=1111111;
headView.backgroundColor=[UIColorcolorWithWhite:0.2 alpha:0.1];
//在view上添加相同大小的按钮
UIButton * button=[[UIButtonalloc]initWithFrame:headView.bounds];
[button addTarget:selfaction:@selector(clickAction:)forControlEvents:UIControlEventTouchUpInside];
//添加三角形图标
UIImageView * imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(5, 5, 40, 40)];
// imageView.userInteractionEnabled=YES;
imageView.image=[UIImageimageNamed:@"disclosure"];
imageView.tag=1001;
//添加组名
UILabel * titleLabel=[[UILabelalloc]initWithFrame:CGRectMake(50, 5, headView.frame.size.width-50, 40)];
titleLabel.textAlignment=NSTextAlignmentCenter;
titleLabel.tag=103;
[headViewaddSubview:titleLabel];
[headViewaddSubview:imageView];
[headViewaddSubview:button];
[hf.contentViewaddSubview:headView];
}
//重新获取headView
UIView * headView=[hf viewWithTag:1111111];
//获取button,设置标题
UIButton * button=[headView.subviewslastObject];
button.tag=section;
//添加分组标题
NSDictionary * temDic=self.dataArray[section];
UILabel * temLabel=(UILabel *)[hfviewWithTag:103];
temLabel.text=temDic[@"group"];
//将刷新的imageView加入到字典
UIImageView * imageView=(UIImageView *)[headViewviewWithTag:1001];
[self.imageDicsetObject:imageView forKey:@(section)];
//消除重复利用图片状态
[selfinitImageStateWithCondition:self.staticDic[@(section)]andSection:section];
return hf;
}
#pragma mark - clickAction
- (void)clickAction:(UIButton *)button{
NSInteger section=button.tag;
//判断是否打开--字典里面信息是否为空
BOOL isOpen=self.staticDic[@(section)]!=nil;
//如果已经打开,则移除里面的信息
//如果没有打开,则加载信息
if(isOpen){
[self.staticDicremoveObjectForKey:@(section)];
}else{
[self.staticDicsetObject:@(1) forKey:@(section)];
}
//折叠动画--刷新数据
NSIndexSet * set=[NSIndexSetindexSetWithIndex:section];
[self.tableViewreloadSections:set withRowAnimation:UITableViewRowAnimationFade];
UIImageView * image=self.imageDic[@(section)];
[selfinitImageStateWithCondition:isOpen andSection:section];
//设置动画,重新判断状态
[UIView animateWithDuration:0.5 animations:^{
if(!isOpen){
image.transform=CGAffineTransformMakeRotation(M_PI_2);
}else{
image.transform=CGAffineTransformIdentity;//恢复原来的状态
}
}];
}
//消除图片重复利用--刷新后先判断图片状态把图片重新快速置为所对应状态,,然后再执行动画
- (void)initImageStateWithCondition:(BOOL)condition andSection:(NSInteger)section{
UIImageView * image=self.imageDic[@(section)];
if(condition){
image.transform=CGAffineTransformMakeRotation(M_PI_2);
}else{
image.transform=CGAffineTransformIdentity;//恢复原来的状态
}
}
//点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"------->联系人信息");
}
@end
- 利用tableView的分组功能进行qq页面设计
- 使用TableView进行分组
- TableView类似QQ分组的折叠与展开
- 利用tableView分组实现省份各个城市的分组,利用首字母作为索引
- 批量爬QQ用户信息,利用QQ查询功能进行获取QQ用户信息
- 用JQuery实现QQ的页面功能
- 实现可折叠的分组tableview
- tabLeview的静态分组使用
- Swift - 使用TableView的静态单元格进行页面布局
- 【利用TableView实现QQ好友列表】
- IOS——TableView 中利用Item模型进行 Cell 的开发(1)TableView 篇
- ios tableView 的cell打开收起功能,类似QQ中的cell折叠功能
- 利用临时变量对每个分组的数据进行累计
- 利用bobo-browse 实现lucene的分组统计功能
- 利用bobo-browse 实现lucene的分组统计功能
- 利用bobo-browse 实现lucene的分组统计功能
- 在tableview的section的头尾里添加控件的方法,如button达到qq分组的效果
- QQ用户分组状态栏功能实现
- Android——自定义Actionbar左侧覆盖不全的解决方案
- unity4.x升级到unity5.x材质丢失
- 剑指offer 22- 包含min函数的栈结构
- Minimum Path Sum leetcode 64
- hdu1286找新朋友 欧拉函数模板题
- 利用tableView的分组功能进行qq页面设计
- 学习IOS开发1
- CentOS6.5 搭建基础PHP环境(yum安装)
- 黑马程序员———java高级特性之泛型
- strace,ltrace linux下跟踪进程调用的命令
- p124第三章45题
- Runtime (二)
- itoa()源码
- 未来 5 年八大热门 IT 职业