1

我试图从我的表格视图中删除一行,但到目前为止一直没有成功。问题是行数据已成功删除,但无法删除表视图的分隔线,因为它是表视图骨架,因为它是数据。

我用来尝试删除行的代码如下。

[autocompleteTableView beginUpdates];
NSLog(@"animationArray Count: %d",[autocompleteSignalsList count]);

for (int i=[autocompleteSignalsList count]-1; i>=0; i--) {
            [autocompleteTableView reloadData];
    NSArray *paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:i inSection:0]];
    [self.autocompleteSignalsList removeObjectAtIndex:i];
    [autocompleteTableView deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
   [autocompleteTableView delegate];
}
[autocompleteTableView endUpdates];

现在对于我希望得到回答的问题:如何正确删除行?

4

1 回答 1

0

分隔线自动出现在空的 UITableView 中。摆脱它的最好方法是为您的 tableView 创建一个页脚。是一个很好的答案,其中包含有关如何执行此操作的信息。

我还会稍微优化你的循环代码:

[autocompleteTableView beginUpdates];
NSLog(@"animationArray Count: %d",[autocompleteSignalsList count]);
NSMutableArray *paths = [NSMutableArray new];
for (int i=[autocompleteSignalsList count]-1; i>=0; i--) {
    [paths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
    [self.autocompleteSignalsList removeObjectAtIndex:i];
}
[autocompleteTableView deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
[autocompleteTableView endUpdates];
于 2012-09-21T14:52:59.920 回答