- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- return YES;
- }
-
- -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return UITableViewCellEditingStyleDelete;
- }
- /*改变删除按钮的title*/
- -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return @"删除";
- }
- /*删除用到的函数*/
- -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (editingStyle == UITableViewCellEditingStyleDelete)
- {
- /*此处处理自己的代码,如删除数据*/
- [dataArray removeObjectAtIndex:indexPath.row]; ( NSMutableArray)
- //删除对应分区中对应行的写
- [[self.dataArray objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
- /*删除tableView中的一行*/
- [tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
- //报错则用 [self.tableView reloadData];
- }
- }
iOS TableView的左划删除以及多个分区的删除某一行的个人笔记
