QQ列表的展开收起

RootViewController.h

@interface RootViewController : UIViewController<UITableViewDataSource,UITableViewDelegate> {

    BOOL Close[15]; //用于存放每一组的收起展开状态    YES 是收起  NO是展开
    UITableView *_tableView;
}

@property(nonatomic, retain)NSArray *data;

RootViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    //创建表视图
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, 320, 460) style:UITableViewStylePlain];
    //设置代理
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.sectionHeaderHeight = 44;

    [self.view addSubview:_tableView];

    //查找文件的路径
    NSString *path = [[NSBundle mainBundle] pathForResource:@"font" ofType:@"plist"];
    _data = [[NSArray alloc] initWithContentsOfFile:path];
}

/*
 _data数据存放的格式
 [
 [@"字体1",@"字体2",@"字体3",@"字体4",@"字体5"],
 [@"字体1",@"字体2",@"字体3"],
 [@"字体1",@"字体2"@"字体5"],
 [@"字体1",@"字体2",@"字体4",@"字体5"],
 ....
 ]
 */

#pragma mark - UITableView dataSource

//设置表视图的组的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return _data.count;
}

//设置每一组cell的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    //取得对应组里面的元素
    NSArray *arrary2D = _data[section];

    BOOL isClose = Close[section];

    if (isClose == NO) {
        return arrary2D.count;
    }

    return 0;

}

/*
 _data数据存放的格式
 [
 [@"字体1",@"字体2",@"字体3",@"字体4",@"字体5"],
 [@"字体1",@"字体2",@"字体3"],
 [@"字体1",@"字体2"@"字体5"],
 [@"字体1",@"字体2",@"字体4",@"字体5"],
 ....
 ]
 */

//创建cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *iden = @"cell110";

    //从闲置池中去cell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden] autorelease];
    }

    NSArray *arrary2D = [_data objectAtIndex:indexPath.section];
    NSString *name = [arrary2D objectAtIndex:indexPath.row];

    //给cell添加数据
    cell.textLabel.text = name;
    cell.textLabel.font = [UIFont fontWithName:name size:17];

    return cell;

}

//设置组的头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    NSString *name = [NSString stringWithFormat:@"好友分组%d",section];

    //创建按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    //设置按钮的背景图片
    [button setBackgroundImage:[UIImage imageNamed:@"tableCell_common"] forState:UIControlStateNormal];
    //设置按钮的标题
    [button setTitle:name forState:UIControlStateNormal];
    button.tag = section;
    //设置按钮显示的标题颜色
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    return button;

}

//按钮的点击事件
- (void)buttonAction:(UIButton *)button {

    int section = button.tag;
    <strong>//将标示取反</strong>
    Close[section] = !Close[section];

    //刷新单元格
//    [_tableView reloadData];

    //刷新特定的组
    NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:section];

    [_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
}
时间: 2024-08-06 05:06:49

QQ列表的展开收起的相关文章

实现列表二级展开/收起/选择

代码地址如下:http://www.demodashi.com/demo/12628.html 1.先看效果图 2.实现原理 1)通过对UITableView进行分组来实现展开收起的功能: 2)通过cell的model和组model中的是否选中和是否展开的标记字段来记录并实现展开/收起/选择的功能: 3.代码实现 1)创建cell的model类并添加如下属性: // 标记是否选中 @property (nonatomic, assign) BOOL isSelect; // 文字 @proper

实现列表展开收起效果

$(".btn").click(function () {$(this).parents("当前元素最外层div的class").toggleClass("showDiv").siblings().removeClass("showDiv");});css:.最外层div class .需要收起展开的div的class{display: none;}.showDiv .需要收起展开的div的class{display: blo

JS+CSS实现可展开/收起的QQ在线客服悬浮代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>JS+CSS实现可展开/收起的QQ在线客服

iOS QQ列表效果实现

效果如下: 实现效果主要分为两个部分: 数据模型 tableview 要实现tableview需要实现DataSource和delegate datasource主要作用在于显示什么数据 delegate主要作用是事件响应即处理 代码如下:.h // controller @interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> @property (nonatomic, 

使用ExpandableListView做一个类似QQ列表效果图

分组列表视图(ExpandableListView) 和ListView不同的是它是一个两级的滚动列表视图,每一个组可以展开,显示一些子项,类似于QQ列表,这些项目来至于ExpandableListAdapter的子类,也就是说,要实现向里面添加项目,必须写一个子类实现ExpandableListAdapter的接口或者使用系统为我们实现在子类 常用属性 1. android:childDivider 指定各组内子类表项之间的分隔条, 2. android:childIndicator 显示在子

展开收起播放列表

//播放器关闭展开播放列表  by sunhw    (function() {        function PlayFold( option ) {            this.option = T.object.extend( {                root           : '',                foldBtn        : '',                playListLayout : '',                packu

仿手机QQ列表支持下拉,上滑,滑动删除

一般安卓程序员都知道下拉刷新主键用 com.handmark.pulltorefresh 网站:https://github.com/chrisbanes/Android-PullToRefresh/ 滑动删除用 fortysevendeg 的 swipelistview 但是要实现QQ列表功能,需要把两者叠加起来,我尝试了一下,发现有Bug, fortysevendeg的代码有点复杂,放弃了,后来自己搞了一个,为了方便广大 安卓程序员,我把整个demo贡献出来. 下载地址:http://pan

Javascript展开收起

<!DOCTYPE html><html><head><meta charset="utf-8" /><title>展开收起</title><style type="text/css">body{ margin: 0 auto; padding: 0px;}#pn{ background: #e8e8e8; width: 600px; height: auto; margin: 0

iOS tableViewCell 在cell赋值、网络加载照片位置偏移大小错乱,做一个类似qq列表的tableview

需求: 类似QQ列表的头像加载刷新,判断在线离线状态改变头像,以及彩色头像灰色处理,下载图片+获取在线状态需要连网--再改变头像 问题:由于cell的复用以及下拉刷新数据每次加载10条数据,会出现头像赋值不正确,位置偏移大小不同的变化 原因:由于cell的重复调用,加载数据方法已经赋值方法也在重复的调用,所以头像加载 在线状态判断好后,网络延迟, (个人开始yy:启动时的cell和赋值结束的cell可能不是同一个) 修改:当cell开始调用的时候,给当前的cell赋tag值,加载结束判断是不是自