类似于qq联系人的tablview能够展开和收缩
来源:互联网 发布:windows官方镜像 编辑:程序博客网 时间:2024/06/06 01:13
在.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能够展开和收缩
- 类似于QQ列表展开和收起的列表
- 模拟QQ列表展开收缩
- QQ列表的收缩展开,带动画效果
- 仿QQ好友的分组收缩展开界面
- UITableView仿QQ好友的分组收缩展开界面
- UITableView仿QQ好友的分组收缩展开界面
- (二十八)QQ好友列表的展开收缩
- JQuery的一种特效:展开和收缩
- Jquery实现的文本展开和收缩
- 可展开和收缩的表格
- jQuery实现图片的展开和收缩
- ExpandableTextView可以展开和收缩的TextView
- WPF TreeView节点的展开和收缩
- ToolBar的滚动展开和收缩
- 封装可展开和收缩的View
- Textview的展开和收缩功能
- 展开和收缩
- C语言运算符优先级 详细列表
- PHP中for循环语句的几种“变态”用法
- linux小记4 查看帮助
- Using Spring.net in console application
- Houdini一键修改Alembic相机分辨率。
- 类似于qq联系人的tablview能够展开和收缩
- position(relative和absolute)
- C++著名类库
- Solaris10 安装curl
- androidの编辑联系人,姓名颠倒bug
- 网线线序接法
- linux 批量 压缩 打包
- 用Emacs远程编辑文件
- 常见操作系统面试题