2014-12-13 56 views

回答

2

你需要的東西是這樣的:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Perform cell change height code here 
    // ... 

    // After that scroll to this cell 
    CGFloat sectionHeaderHeight = [self tableView:tableView heightForHeaderInSection:indexPath.section]; 
    CGRect cellFrame = [tableView rectForRowAtIndexPath:indexPath]; 
    [tableView setContentOffset:CGPointMake(0, cellFrame.origin.y - sectionHeaderHeight) animated:YES]; 
} 
+0

是的,就像維塔利說的那樣,你需要這樣的解決方案。 -setContentOffset部分是至關重要的。 – Igor 2014-12-13 17:44:27

+0

這類作品,但是爲了將單元格帶到頂部,需要添加一個contentInset,在完成頂部單元格之後,您可能想要刪除它。 – 2014-12-14 15:32:08

+0

@StefanKendall你說得對,有兩種方法可以實現這一點 - 像你說的那樣添加底部內容插入,或者在表格內容大小的末尾檢查單元格的框架並適當修正內容偏移 – 2014-12-14 22:35:53

1

scrollToRowAtIndexPath...scrollToNearestSelectedRow...都採取「滾動位置」參數,允許選擇去頂部,中部或底部的表格視圖。這應該給你你想要的。

+0

scrollToRow將單元格放置在導航欄下方。 – 2014-12-13 20:52:59

+0

噢,即使調整了滾動視圖上的插頁嗎?當你不是在調整單元格大小時,它會這麼做嗎?聽起來像一個錯誤。 – jrturton 2014-12-14 11:11:15