tablerow delete but still showon in table view

2019-03-06 03:46发布

my data is show on the table whn i select data to delet its delted from database but not from table , i go back to other view and again come to the delete table view then delete data is not show again i am using this code ...

- (void)deleteRowsAtIndexPaths:(NSArray *)indexPath withRowAnimation:(UITableViewRowAnimation)animation
{

    NSLog(@"Hello");

}


-(void) tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath 

{
//  int row = [indexPath row];
    [self.table beginUpdates];
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {   
        Hadits *delHadit = [self.allBookMarks objectAtIndex:indexPath.row];
        dbAccess *dbmethods = [[dbAccess alloc] init]; 
        NSInteger delHaditid = delHadit.haditid;
        [dbmethods deleteBookMark:delHaditid];
        [dbmethods release];
    }       

    [self deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                          withRowAnimation:UITableViewRowAnimationFade];
    [self.table endUpdates];

    NSLog(@"Hello");
    [self.table reloadData];

}

...Help needed.. Regards Haseeb

2条回答
一纸荒年 Trace。
2楼-- · 2019-03-06 04:17

in view will appear prepare your array which having record and in commitEditing add one line.

[self viewWillApear:YES];

and in viewWillAppear add this line

[yourTable reloadData];

after fetching data from db.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-03-06 04:39

There is little mistake (or I think the relevant code is not shown). You have deleted the entry from the database, but I think you have missed to delete the same from your array which acts as your tableview datasource.

-(void) tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    [self.table beginUpdates];

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {   
    //  [self.table deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:UITableViewRowAnimationFade];
        Hadits *delHadit = [self.allBookMarks objectAtIndex:indexPath.row];
        dbAccess *dbmethods = [[dbAccess alloc] init]; 
        NSInteger delHaditid = delHadit.haditid;
        [dbmethods deleteBookMark:delHaditid];
        [dbmethods release];
        [self.allBookMarks removeObject:delHadit];/// change of code 
    }
    //[self.table reloadData];
    [table endUpdates];
}
查看更多
登录 后发表回答