开发者

tablerow delete but still showon in table view

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


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜