Delete Rows from UITableView

为君一笑 提交于 2019-12-06 15:02:25

You don't appear to be calling the UITableView reloadData method at any point after you've carried out the deletion.

As such, adding...

[tableView reloadData];

...to the bottom of your - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath method should solve the problem.

Well, you either need to call reloadData or – deleteRowsAtIndexPaths:withRowAnimation:.

I have two thoughts on this:

1) You can delete the row in the commitEditingStyle:... method. Here's an example from Apple's "Locations" sample code

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];

Search the documentation for commitEditingStyle: and you'll find other examples.

2) It looks like you've added code to viewDidLoad to configure the table view. It would be a good idea to remove that code and put it in a separate method such as

- (void) updateMyTableView
{
     // Code to reload the table view.
}

and then calling it where ever you need it. Calling viewDidLoad directly is not such a good idea because it usually does other things such as '[super viewDidLoad]' which aren't needed to update the table view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!