1

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?

Bart
  • 19,692
  • 7
  • 68
  • 77
user196320
  • 97
  • 1
  • 3
  • 8
  • Reload the table after U are Deleting the row or better try to look at this link http://www.roseindia.net/tutorial/iphone/examples/iphone-DeleteandaddrowfromTableView.html – Manikandan Sep 21 '12 at 12:39

1 Answers1

0

The separator line appears automatically in an empty UITableView. The best way to get rid of it is to create a footer for your 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];
Community
  • 1
  • 1
Igor N
  • 381
  • 2
  • 6
  • thanks for solution but problem is that only remove seperator line not removes table view. but I want to remove table as well – user196320 Sep 24 '12 at 10:24
  • I am a bit confused as to what you are looking to do. Do you want to remove the whole table? Or do you want to resize the table so that it is only as wide as the number of cells with data in them? – Igor N Sep 27 '12 at 11:21
  • Hey, I want to remove the tableview but when I remove tableview but animation effect is gone. – user196320 Oct 01 '12 at 06:31
  • If you want to remove the whole tableView with an animation you can use something like this: `[UIView transitionWithView:tableView duration:3.0 options:UIViewAnimationOptionTransitionNone animations:^{ tableView.frame = CGRectOffset(tableView.frame, -tableView.frame.size.width, 0); } completion:^(BOOL finished) { [tableView removeFromSuperview]; }];` – Igor N Oct 02 '12 at 09:15
  • thanks for above solution but from above solution I will not get table view up animantion How I can achieve this – user196320 Oct 03 '12 at 06:17
  • You can change the animation by replacing `UIViewAnimationOptionTransitionNone` with a different one. I am not sure what exactly you mean by "table view up animation". Can you clarify please. – Igor N Oct 04 '12 at 11:42