2012-02-16 92 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:方法