简体   繁体   English

无法从iPhone中的UItable视图删除行?

[英]Unable to deleting row from UItable view in iPhone?

I'm trying to delete a row from my table view and so far have been unsuccessful. 我正在尝试从表格视图中删除一行,但到目前为止没有成功。 The problem is that row data is deleted successfully but unable to delete seperator line of table view that's table view skeleton seen as it is rather data. 问题在于,行数据已成功删除,但无法删除表视图的分隔线,该分隔符是表视图框架,因为它实际上是数据。

The code that I used to try deleting rows is as follows. 我用来删除行的代码如下。

[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];

Now for the questions I hope to get answered: How can I delete rows properly? 现在,我希望得到解答的问题:如何正确删除行?

The separator line appears automatically in an empty UITableView. 分隔线自动显示在一个空的UITableView中。 The best way to get rid of it is to create a footer for your tableView. 摆脱它的最好方法是为tableView创建页脚。 This is a good answer with information on how to do this. 是一个很好的答案,提供有关如何执行此操作的信息。

I would also optimise your loop code a bit: 我还将优化您的循环代码:

[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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM