#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;
}
}