您可以通過一種無形的頁腳修復它,做計算在裏面。當頁腳被加載時,contentSize被更新。爲了讓它滾動,我檢查設置tableview的contentOffset。
我已經註釋掉了動畫部分,因爲你不需要它,但它也可以。
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if(tableView.contentOffset.y != tableView.contentSize.height - tableView.frame.size.height && automaticScroll){
//[UIView animateWithDuration:0.0 animations:^{
self.contentTableView.contentOffset = CGPointMake(0, tableView.contentSize.height - self.contentTableView.frame.size.height);
//} completion:^(BOOL finished) {
[tableView reloadData];
//}];
automaticScroll = NO;
}
UIView *emptyFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
emptyFooter.backgroundColor = [UIColor clearColor];
return emptyFooter;
}
我創建了一個BOOL自動滾動觸發滾動到底部。這應該在viewWillAppear方法中設置,或者在您加載數據並重新加載tableView時進行設置。
如果你想添加行,你還需要設置BOOL,如:
-(void)addItemButtonClicked:(id)sender
{
automaticScroll = YES;
//Add object to data
[self.contentTableView reloadData];
}
如果您需要更多的幫助,請讓我知道。
你可以嘗試用翻轉180°表視圖,翻轉你自定義表格視圖單元格180°,因此它們看起來很正常,並顛倒了索引路徑的邏輯。你將在你的tableview的底部有0行。 – Moxy
這似乎是一個可怕的很多工作。只需反轉切換第一個對象的最後一個對象的數據源,依此類推。然後你會以相反的順序顯示它。 – Martol1ni
@ Martol1ni它只有2行代碼! – Moxy