вторник, 24 июля 2012 г.

How to delete a row in UITableView manually?

To delete row from table manually (programmatically) at first remove items from array with table items, which you use to build table cells. Then you should use method

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
Where instead of
[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]]
you should use your array with index paths. Here just first row will be removed.
And don't forget to wrap this method into
[self.tableView beginUpdates];
...
[self.tableView endUpdates];
So in conclusion this code should looks like this

[self.itemsArray removeObjectAtIndex:0];
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];

Комментариев нет:

Отправить комментарий