tablerow delete but still showon in table view

泪湿孤枕 提交于 2019-12-02 17:52:38

问题


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


回答1:


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.




回答2:


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];
}


来源:https://stackoverflow.com/questions/4942326/tablerow-delete-but-still-showon-in-table-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!