0

我正在尝试在表格的开头插入一行,但我想保持以前内容的位置(类似于加载更多推文时的 Twitter 应用程序),目前我正在使用以下代码:

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


4

1 回答 1

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
}

注意:这是基于这样的假设,即在填充表中的数据时,您会按顺序遍历数组中的每个对象。

于 2012-05-15T14:08:45.783 回答