2012-05-15 53 views
0

我試圖在表格的開頭插入一行,但我想保持以前內容的位置(類似於Twitter應用程序時負載更多的鳴叫),此刻我正在使用下面的代碼:將行插入到UITableView而不更改之前內容的位置

 
- (void) insertObject: (id) object 
{ 
    [_objects insertObject: object atIndex: 0]; 
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0]; 
    [[self tableView] insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
} 


+0

問題是什麼? – Eimantas

+0

我認爲他會保留插入後的實際位置。 所以如果tableview顯示單元格1-5並且他在位置0上插入一行。那麼可見行應該是1-5而不是0-4。 – mafis

+0

沒錯,問題是在顯示的行之前插入行後保持當前位置。 – xlarsx

回答

0

我不知道我完全理解這個問題是在這裏。也就是說,如果你真的只是想在表的頂部插入新行,那麼爲什麼你就不能做到以下幾點:

- (void) insertObject: (id) object 
{ 
    [_objects insertObject: object atIndex: 0]; // Add the new object to the array (position 0) 
    [self.tableView reloadData]; // Reload the data in the table 
} 

注:這是基於這樣的假設,當填充您的表中的數據按順序遍歷數組中的每個對象。