Swipe To Delete TableView Row

后端 未结 8 1000
暖寄归人
暖寄归人 2020-12-24 06:10

I have my array:

self.colorNames = [[NSArray alloc] 
initWithObjects:@\"Red\", @\"Green\",
@\"Blue\", @\"Indigo\", @\"Violet\", nil];

I\'ve

8条回答
  •  抹茶落季
    2020-12-24 06:52

    You have to implement the necessary UITableViewDelegate and UITableViewDataSource methods.

    First, add this:

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
        return YES;
    }
    

    Then:

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            //remove the deleted object from your data source.
            //If your data source is an NSMutableArray, do this
            [self.dataArray removeObjectAtIndex:indexPath.row];
            [tableView reloadData]; // tell table to refresh now
        }
    }
    

提交回复
热议问题