I have implemented this swipe to delete but as a clear button that resets the uitableviewcells textlabel to empty... when this method is executed it works perfectly.. however when the user touches the same cell after the swipe to clear nothing happens... then if you touch it again it works perfectly... here is my code..
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
//[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
//reset uitableviewcell textlabel with default input "empty"
vehicleSearchObjectString = @"empty";
开发者_如何学C [self.tableView reloadData]; //reloads the tabels so you can see the value.
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
You need to delete your object from the data source. I see you have that line commented out where you delete the row at the given index path, but you also actually need to delete your object from whatever list or structure is holding your objects that are displayed in the table to begin with.
I don't know if that's what's causing your problem, but I've had a bunch of problems with this in the past because I forgot to delete my object properly.
精彩评论