iOS TableView实现QQ好友列表(三)

本文介绍如何在iOS中实现QQ好友列表的分组点击时进行折叠和展开。通过在TableView的section header上添加button,并利用tag属性区分不同分组,实现了点击按钮控制列表显示状态。最后展示了实现后的效果,并提供了源代码分享的途径。
摘要由CSDN通过智能技术生成

上节我们讲到如何展示好友信息

iOS TableView实现QQ好友列表(二)

http://blog.csdn.net/lwjok2007/article/details/46549111



接下来我们将分组点击的时候折叠起来。


首先新建一个可变字典用来存储当前列表是否展示



    NSMutableArray *selectedArr;//控制列表是否被打开

    selectedArr=[[NSMutableArray alloc]init];


根据前两节所讲,我们讲分组名称放在section的header上了,但是Header 不像cell一样有点击方法

此时我们可以考虑给header上添加一个button来实现点击的时候打开列表和关闭列表


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
    view.backgroundColor=[UIColor whiteColor];
    
    UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 5, SCREEN_WIDTH, 30)];
    titleLabel.text=[titleArray objectAtIndex:section];
    [view addSubview:titleLabel];
    
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 20, 20)];
    imageView.tag=20000+section;
    
    imageView.image=[UIImage imageNamed:@"arrow_down.png"];
    [view addSubview:imageView];
    
    //添加一个button 用来监听点击分组,实现分组的展开关闭。
    UIButton *btn=[UIButton buttonWithType:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值