2012-02-16 94 views
1

我有一个2行的表格视图。最初相应地设置行高。然后我加载另一个视图控制器,显示一个列表,用户可以从中选择多个项目。这些项目将作为自定义图像在桌面视图的第一行绘制。当用户点击后面,显示在用户选择的项目selelction,但我需要能够调整行的高度为0动态更改tableview行高

+0

你在打电话reloadData选择某个项目后的原始表格视图? – sosborn 2012-02-16 12:15:16

+0

我需要检查一下。我相信如此,但会确认 – 2012-02-16 12:20:56

回答

1

试试这个:在您TableListController

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

+0

我已经使用该代码来设置初始行高度,但当用户选择要显示的项目后返回表格时,它不会再次被触发。 – 2012-02-16 12:09:03

+1

大概尝试'[tableview reloadData];'刷新tableview并应用新的高度。 – iDifferent 2012-02-16 12:13:38

0

头文件中声明:

@property (nonatomic, retain) NSIndexPath * expandedCellIndexPath; 

然后在.M添加

- (void)changeCellHeights:(NSIndexPath *)indexPath 
{ 
    if (self.expandedCellIndexPath) { 
     [self.yourTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject: self.expandedCellIndexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    self.expandedCellIndexPath = indexPath; 
    [self.yourTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject: self.expandedCellIndexPath] withRowAnimation:UITableViewRowAnimationMiddle]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    DebugLog(@""); 
    if (self.expandedCellIndexPath && indexPath.row == self.expandedCellIndexPath.row && indexPath.section == self.expandedCellIndexPath.section) { 
     return 80; 
    } 
    return 56.0; 
} 

最后不要忘记设置你的TableCell到剪辑子视图(在你的XIB,如果你使用一个)

你现在需要的是调用changeCellHeights:方法