在.h文件中定义三个数组和一个tablview

UITableView *listTable;
    NSMutableArray *listArray;
    NSMutableArray *proviceArray;
    NSMutableArray *statusArray;

//定义一个点击方法

-(void)ClickTheSection:(int)section;

在.m文件中使用

//先声明数组和tablview并给数组赋初值

- (void)viewDidLoad
{
    [super viewDidLoad];

listTable=[[[UITableView alloc]initWithFrame:CGRectMake(0, 70, 320, 390) style:UITableViewStylePlain]autorelease];
    listTable.showsVerticalScrollIndicator=NO;
    listTable.backgroundColor=[UIColor whiteColor];
    listTable.dataSource=self;
    listTable.delegate=self;
    [self.view addSubview:listTable];

listArray=[[NSMutableArray alloc]initWithObjects:@"河南",@"郑州",@"安阳",@"许昌",@"周口",@"南阳",@"信阳", nil];
    proviceArray=[[NSMutableArray alloc]initWithObjects:@"河南",@"河北",@"湖南",@"湖北",@"广东",@"广西",@"山西", nil];
    statusArray=[[NSMutableArray alloc]initWithObjects:@"0",@"0",@"0",@"0",@"0",@"0",@"0", nil];
    
}

#pragma mark-tablview的相关设置
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([[statusArray objectAtIndex:section]integerValue]) {
        return listArray.count;
    }else{
        return 0;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
#pragma tablview的cell赋值方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identfer=@"UItableviewCell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identfer];
    if (cell==nil) {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identfer]autorelease];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle=UITableViewCellSelectionStyleGray;
        
        
        
    }    
    cell.textLabel.text=[listArray objectAtIndex:indexPath.row];
    return cell;
    
    
}
#pragma mark-tablview的section设置
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIImageView *imagView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 100)];
    imagView.backgroundColor=[UIColor clearColor];
    imagView.userInteractionEnabled=YES;
    [imagView setImage:[UIImage imageNamed:@"sectionbg.png"]];
    
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"buttonbg.png"] forState:UIControlStateNormal];
    button.frame=CGRectMake(0, 10, 320, 80);
    [button setTitle:[proviceArray objectAtIndex:section] forState:UIControlStateNormal];
    button.tag=section;
    [button addTarget:self action:@selector(ClickTheSection:) forControlEvents:UIControlEventTouchUpInside];
    [imagView addSubview:button];
    
    return imagView;
        
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 100;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return proviceArray.count;
    
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return @"123";
    }
    else if (section==1)
    {
        return @"456";
    }
    else{
        return @"789";
    }
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    NSArray *array=[NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z", nil];
    return array;
}
#pragma mark-移动问题

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    [listArray exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];
    [listTable  reloadData];
    
}
#pragma mark-点击某个section的效应
-(void)ClickTheSection:(int)section
{
    UIButton *button=(UIButton*)section;
    if ([[statusArray objectAtIndex:button.tag]integerValue]==0) {
        [statusArray replaceObjectAtIndex:button.tag withObject:@"1"];
    }
    else{
        [statusArray replaceObjectAtIndex:button.tag withObject:@"0"];
    }
    [listTable reloadData];
    
}

#pragma mark-点击按钮触发事件

-(void)ClickEditButton
{
    if (listTable.editing==YES) {
        [listTable setEditing:NO animated:YES];
    }
    else{
        [listTable setEditing:YES animated:YES];
    }

}

类似于qq联系人的tablview能够展开和收缩的更多相关文章

  1. JS时间轴效果(类似于qq空间时间轴效果)

    在上一家公司写了一个时间轴效果,今天整理了下,感觉有必要写一篇博客出来 给大家分享分享 当然代码还有很多不足的地方,希望大家多指点指点下,此效果类似于QQ空间或者人人网空间时间轴效果,当时也是为了需求 ...

  2. 动手分析安卓仿QQ联系人列表TreeView控件

    因项目需要需要用到仿QQ联系人列表的控件样式,于是网上找到一个轮子(https://github.com/TealerProg/TreeView),工作完成现在简单分析一下这个源码.   一. 需要用 ...

  3. 自定义控件--CircleImageView(类似于QQ、微信圆形头像自定义控件)

    现在基本上所有的需要用户注册的APP都有一个需要用户上传头像的需求,上传的头像基本都是类似于QQ.微信等社交应用圆形头像.最近,正在做的一个社交应用多处需要用到这种圆形头像的处理,总不能每次都对图片做 ...

  4. 一个关于如何创建类似于QQ客户端聊天窗口的模拟小项目

    对于不久之前学习到的一个有关的类似于QQ聊天框的模拟项目,对其中涉及到的知识在这里做一下总结. 首先,你要先创建一个客户端聊天框(取名为:ChatClient,它是你创建的类),这个类继承了Frame ...

  5. 类似于qq空间类型的评论和回复

    最近学习thinkphp,做了一个博客系统,其中感觉实现一个类似于qq空间的评论和回复功能比较复杂,所以把这次的经历记录下来,与大家共勉,具体的方法就不说了,在这里分享一下思路. 目标就是这种,关键是 ...

  6. WPF 自定义TreeView控件样式,仿QQ联系人列表

    一.前言 TreeView控件在项目中使用比较频繁,普通的TreeView并不能满足我们的需求.因此我们需要滴对TreeView进行改造.下面的内容将介绍仿QQ联系人TreeView样式及TreeVi ...

  7. 查看图片插件--Viewer(类似于qq和微信聊天 的查看图片)

    Viewer的github地址:https://github.com/fengyuanchen/viewer  下载该插件(在文件夹dist里面) 具有参考价值的几个网站:http://www.dow ...

  8. DataGridView之行的展开与收缩

    很多数据都有父节点与子节点,我们希望单击父节点的时候可以展开父节点下的子节点数据. 比如一个医院科室表,有父科室与子科室,点击父科室后,在父科室下面可以展现该科室下的所有子科室. 我们来说一下在Dat ...

  9. ios知识点总结——UITableView的展开与收缩及横向Table

    UITableVIew是iOS开发中使用最为广泛的一种控件,对于UITableView的基本用法本文不做探讨,本文主要是针对UITableView的展开与收缩进行阐述,在文章的后面也会探讨一下横向ta ...

随机推荐

  1. IT大数据服务管理高级课程(IT服务,大数据,云计算,智能城市)

    个人简历 金石先生是马克思主义中国化的研究学者,上海财经大学经济学和管理学硕士,中国民主建国会成员,中国特色社会主义人文科技管理哲学的理论奠基人之一.金石先生博学多才,对问题有独到见解.专于工作且乐于 ...

  2. VC socket Connect 超时时间设置

    设置connect超时很简单,CSDN上也有人提到过使用select,但却没有一个令人满意与完整的答案.偶所讲的也正是select函数,此函数集成在winsock1.1中,简单点讲,"作用使 ...

  3. JavaScript判断横屏/竖屏

    /判断手机横竖屏状态:  function hengshuping(){    if(window.orientation==180||window.orientation==0){          ...

  4. error -27257: Pending web_reg_save_param/reg_find/create_html_param[_ex] request(s) detected and reset at the end of iteration number 1

    检查点函数  web_reg_find("Search=body",     "savecount=num",     "Text=test1&quo ...

  5. Head First PHP &MySQL学习笔记

      近期一段时间在学习PHP,买了<Head First PHP&MySQL>中文版这本书,之前买过<Head First设计模式>,感觉这系列的书籍整体来说非常不错. ...

  6. 深入理解extern使用方法

    一. extern做变量声明 l  声明externkeyword的全局变量和函数可以使得它们可以跨文件被訪问. 我们一般把全部的全局变量和全局函数的实现都放在一个*.cpp文件中面,然后用一个同名的 ...

  7. CSDN头版头条 《近匠》 Wijmo 5 CTO:从Web到移动,我的25年编程生涯

    现年52岁的Bernardo Castilho先生是GrapeCity(中文名为葡萄城)ComponentOne公司的CTO,在与他的对话过程中.充满风趣严谨和厚重的历史感. 当作为年轻人的我们崇拜着 ...

  8. 设计模式之Prototype(c++)

    Prototype模型: 作用: 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象----克隆(clone)对象. Prototype模型类图如下: 形象说明:如果客户想配钥匙(Conc ...

  9. WindowsPhone8中实现圆形图片的生成显示

    原文 WindowsPhone8中实现圆形图片的生成显示 很多软件中(比如QQ)用到了许多圆形图片,作为用户头像等等,原始图片往往是方形的,那么怎么样将方形的图片显示成圆形呢? 一种方法是当背景为固定 ...

  10. 9.7寸RK3188瑞芯微四核爱立顺M33平板电脑 - 深圳吉祥星晨科技有限公司 - 华强商情网

    9.7寸RK3188瑞芯微四核爱立顺M33平板电脑 - 深圳吉祥星晨科技有限公司 - 华强商情网 欢迎加入 2000人超级QQ群,平板电脑行业交流群:221371451,平板电脑产品及报价群:5765 ...