I want to delete the row of my
tableView
. I can delete the row from database but the row in my tableview does not dissapear. Thanks a lot!!! Mayte
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
PFUser *user = [self.allProducts objectAtIndex:indexPath.row];
[_mipedido removeObject:[PFObject objectWithoutDataWithClassName:@"almacen"objectId:user.objectId]];
[[PFUser currentUser] saveInBackground];
NSMutableArray *pedido = [[NSMutableArray alloc] init];
for (int i = 0; i <= 1; i++)
{
[pedido removeObject:[NSIndexPath indexPathForItem:i inSection:1]];
}
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:pedido withRowAnimation:NO];
[tableView endUpdates];
}
[tableView reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier =@"editSnacksTableViewCell";
editSnacksTableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
NSArray *nib =[[NSBundle mainBundle] loadNibNamed:@"editSnacks" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
PFUser *user = [self.allProducts objectAtIndex:indexPath.row];
cell.precio.text = [NSString stringWithFormat:@"%f",[[precioProducto text] doubleValue]];
cell.nombreProducto.text =user[@"nombreProducto"];
// cell.photoSnacks.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
// cell.descripcionSnakcs.text =[tableData objectAtIndex:indexPath.row];
return cell;
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
self.mipedido = [[PFUser currentUser] objectForKey:@"mipedido"];
PFQuery *query = [self.mipedido query];
// [query whereKey:@"nombreProducto" notEqualTo:self.currentUser.username];
[query orderByAscending:@"nombreProducto"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@"Error %@ %@", error, [error userInfo]);
}
else {
self.allProducts =objects;
[self.tableView reloadData];
}
}];
}