自己写的UITableView的折叠效果
来源:互联网 发布:软件设计师通过率 编辑:程序博客网 时间:2024/06/05 04:19
//
// FoldViewController.m
// FoldTableView
//
// Created by wuyang on 13-11-7.
// Copyright (c) 2013年 wy. All rights reserved.
//
#import "FoldViewController.h"
#import "SuperCell.h"
#import "ChildrenCell.h"
@interface FoldViewController ()
@end
@implementation FoldViewController
@synthesize datalist = _datalist;
@synthesize tableView = _tableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
NSString *path = [[NSBundlemainBundle] pathForResource:@"ExpansionTableTestData"ofType:@"plist"];
_datalist = [[NSMutableArrayalloc] initWithContentsOfFile:path];
NSLog(@"%@",path);
// NSLog(@"data = %@",_datalist);
_tableView = [[UITableViewalloc] initWithFrame:CGRectMake(0,0, 320,460) style:UITableViewStylePlain];
_tableView.delegate =self;
_tableView.dataSource =self;
_tableView.autoresizingMask =UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_tableView.backgroundColor = [UIColorclearColor];
[self.viewaddSubview:_tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [_datalistcount];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//判断当前section开关状态:YES(开) , NO(关)
BOOL select = [(NSNumber*)[[_datalistobjectAtIndex:section] objectForKey:@"Select"]boolValue];
if (select == YES)
{
return [[[_datalistobjectAtIndex:section] objectForKey:@"list"]count]+1;
}
return 1;
}
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
BOOL select = [(NSNumber*)[[_datalistobjectAtIndex:indexPath.section] objectForKey:@"Select"]boolValue];
if (select == YES)
{
if (indexPath.row >0)
{
return 80;
}
}
return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BOOL select = [(NSNumber*)[[_datalistobjectAtIndex:indexPath.section] objectForKey:@"Select"]boolValue];
if (select == YES&&indexPath.row !=0)
{
//子类cell
ChildrenCell *cell = (ChildrenCell*)[tableViewdequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[ChildrenCellalloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:nil];
}else{
while ([cell.contentView.subviewslastObject] != nil) {
[(UIView*)[cell.contentView.subviewslastObject] removeFromSuperview]; //删除并进行重新分配
}
}
cell.selectionStyle =UITableViewCellSelectionStyleNone;
NSArray *list = [[_datalistobjectAtIndex:indexPath.section] objectForKey:@"list"];
cell.titleLabel.text = [listobjectAtIndex:indexPath.row-1];
if (indexPath.row ==1)
{
UIImageView *upimg = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, 320,5)];
upimg.backgroundColor = [UIColorclearColor];
upimg.image = [UIImageimageNamed:@"down.png"];
[cell.contentView addSubview:upimg];
}
if (indexPath.row == [listcount])
{
UIImageView *upimg = [[UIImageViewalloc]initWithFrame:CGRectMake(0,75, 320,5)];
upimg.backgroundColor = [UIColorclearColor];
upimg.image = [UIImageimageNamed:@"up.png"];
[cell.contentView addSubview:upimg];
}
return cell;
}else
{
//父类cell
SuperCell *cell = (SuperCell*)[tableViewdequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[SuperCellalloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:nil];
}else{
while ([cell.contentView.subviewslastObject] != nil) {
[(UIView*)[cell.contentView.subviewslastObject] removeFromSuperview]; //删除并进行重新分配
}
}
cell.selectionStyle =UITableViewCellSelectionStyleNone;
// [cell changeArrowWithUp:NO];
NSString *name = [[_datalistobjectAtIndex:indexPath.section] objectForKey:@"name"];
cell.titleLabel.text = name;
return cell;
}
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row ==0)
{
//动画开始
[self.tableViewbeginUpdates];
BOOL select = [(NSNumber*)[[_datalistobjectAtIndex:indexPath.section] objectForKey:@"Select"]boolValue];
// SuperCell *cell = (SuperCell*)[self.tableView cellForRowAtIndexPath:indexPath];
if (select == 0)
{
// [cell changeArrowWithUp:YES];
[self OnChildrenCell:indexPath.sectionUp:select];
} else
{
// [cell changeArrowWithUp:NO];
[self OffChildrenCell:indexPath.sectionUp:select];
}
//动画结束
[self.tableViewendUpdates];
}else
{
//子层触发事件
NSDictionary *dic = [_datalistobjectAtIndex:indexPath.section];
NSArray *list = [dic objectForKey:@"list"];
NSString *item = [list objectAtIndex:indexPath.row-1];
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:item message:nil delegate:nil cancelButtonTitle:@"取消"otherButtonTitles: nil];
[alert show];
}
}
//打开子列表
-(void)OnChildrenCell:(NSUInteger)index Up:(BOOL)up
{
[[_datalistobjectAtIndex:index] removeObjectForKey:@"Select"];
[[_datalistobjectAtIndex:index] setObject:@"1"forKey:@"Select"];
NSMutableArray * indexPathTosection = [NSMutableArrayarray];
for (int i = 1; i<[[[_datalist objectAtIndex:index]objectForKey:@"list"] count]+1; i++)
{
NSIndexPath *indexPath = [NSIndexPathindexPathForRow:i inSection:index];
[indexPathTosection addObject:indexPath];
}
//插入子类cell
[self.tableViewinsertRowsAtIndexPaths:indexPathTosection withRowAnimation:UITableViewRowAnimationTop];
//打开方式
[self.tableViewscrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionNoneanimated:YES];
}
//关闭子列表
-(void)OffChildrenCell:(NSUInteger)index Up:(BOOL)up
{
[[_datalistobjectAtIndex:index] removeObjectForKey:@"Select"];
[[_datalistobjectAtIndex:index] setObject:@"0"forKey:@"Select"];
NSMutableArray * indexPathTosection = [NSMutableArrayarray];
for (int i = 1; i<[[[_datalist objectAtIndex:index]objectForKey:@"list"] count]+1; i++)
{
NSIndexPath *indexPath = [NSIndexPathindexPathForRow:i inSection:index];
[indexPathTosection addObject:indexPath];
}
//移除子类cell
[self.tableViewdeleteRowsAtIndexPaths:indexPathTosection withRowAnimation:UITableViewRowAnimationTop];
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- 自己写的UITableView的折叠效果
- UITableView的折叠效果
- UITableView的折叠效果
- UITableView 的折叠状态
- UItableview点击后的折叠效果的简单实现
- UITableView的折叠收缩和QQ好友分组效果
- UITableView的折叠收缩和QQ好友分组效果
- UITableView的折叠收缩和QQ好友分组效果
- 自定义UITableView折叠效果
- UITableView 折叠效果 masksToBounds
- 自定义UITableView折叠效果
- UITableView的折叠与展开
- 自己写的简单的折叠板例子
- 自定义UITableView折叠效果类似于QQ的那种折叠效果。只刷新点击的折叠行。不加载所有数据源。 测试环境Xcode4.3.3+SDK5.1兼容ios6
- 一个简单的折叠效果
- 实现折叠的uitableviewcell效果
- TextView的折叠动画效果
- 自己写的”图片轮换效果“代码
- IOS 调用拨打电话
- Android 漫游之路------直接拿来用!最火的Android开源项目(2)
- 下载远程附件php
- java synchronized详解 二
- 第十一周项目1-调用函数输出星号图
- 自己写的UITableView的折叠效果
- 青苹果jsunpack学习(一)windows下安装运行
- kali linux 1.05安装笔记
- Linux 网络协议栈协议的处理
- Visual Studio 2013 a new feature, Code Lens
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
- mysql根据时间戳查询指定日期内数据
- UVa 846 Steps
- ls