您的位置:首页 > 其它

刷新tableView单行 实现折叠效果

2013-10-21 09:33 453 查看
#define originalHeight 25.0f
#define newHeight 85.0f
#define isOpen @"85.0f"

1、创建好tableView
2、
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath函数中设定的显示为展开后的显示
3、设置点击后的效果,行高变换

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row ==
0) {
UITableViewCell *targetCell = [tableView
cellForRowAtIndexPath:indexPath];
if (targetCell.frame.size.height ==
originalHeight+1){
[dicClicked setObject:isOpen
forKey:indexPath];
}
else{
[dicClicked removeObjectForKey:indexPath];
}
[self.tableView
reloadRowsAtIndexPaths:[NSArray
arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];//刷新这一行
}
NSLog(@"indexPath=%@",indexPath);
NSLog(@"dicClicked=%@",dicClicked);
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row ==
0) {
if ([[dicClicked
objectForKey:indexPath] isEqualToString:
isOpen])
return [[dicClicked
objectForKey:indexPath] floatValue];
else
return originalHeight;
}
else {
return 45.0f;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: