2013-01-06 105 views

回答

17

实际上很简单,为NSIndexPath创建一个实例变量,我称之为selectedIndexPath。然后你需要做的就是在heightForRowAtIndexPath的条件下调整这个特定单元格的高度。

然后在didSelectRowAtIndexPath中将选定的索引路径iVar设置为所选单元的路径,并调用该表的开始/结束更新。该单元格会自动展开,并有一个很好的动画。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    selectedIndexPath = indexPath; 
    [self.tableView beginUpdates]; 
    [self.tableView endUpdates]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if ([indexPath compare:selectedIndexPath] == NSOrderedSame) { 
     return 80; 
    } 
    return 40; 
}