我有一個表格,其中當用戶點擊一個單元格時,細節單元格下降到它的正下方。我已經想出瞭如何使用insertRowAtIndexPath
來實現這一點,但是細節單元的行高比正常單元高。我試過heightForRowAtIndexPath
,但似乎只是在初始加載視圖時調用(或使用reloadData
)。但是,我不希望將細節單元格添加到表格視圖的數據中,因此可以將reloadData
消除,因此可以刪除heightForRowAtIndexPath
。我有一個自定義UITableViewCell
分類爲ItemDetailCell
。我認爲這可能會從故事板中的關聯單元格加載指定的行高,但似乎不起作用。這是我在cellForRowAtIndexPath
怎樣努力:用insertRowAtIndexPath調整UITableViewCell高度
if (indexPath.row == _detailCellIndexPath.row && _detailCellIndexPath) {
NSLog(@"detailCell");
ItemDetailCell *detailCell = [tableView dequeueReusableCellWithIdentifier:DetailCellIdentifier forIndexPath:_detailCellIndexPath];
//customize cell
return detailCell;
}
else {
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//customize cell
return cell;
}
我得到在控制檯中NSLog(@"detailCell")
的回報,所以我知道它獲取調用,但它仍然不調整單元格高度。
任何幫助,非常感謝!提前致謝。
由於詳細信息單元是我在Master-Detail模板中詳細信息視圖的版本,因此它只是臨時的,並不是表格中的永久添加項,因此我不希望它在備份數據中,因爲我必須不斷移除它。如果可以的話,這是我想避免的。 –
@MusicMathTech reloadData動畫效果不佳。如果用戶有辦法顯式插入/刪除行(例如通過點擊單元格),推薦的方法是將插入/刪除代碼放入beginUpdates endUpdates動畫塊中。 –