Search code examples
objective-cuitableviewbookmarksdelete-row

Selected row is not deleting from UITableView


I am doing Bookmark module for my application. when i delete the row from TableView the last row from the table gets deleted,But from database the the selected row gets deleted. The problem is while displaying the data in tableview

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

    [[UIBarButtonItem appearanceWhenContainedIn:[UIPopoverController class], nil]
     setTintColor:[UIColor grayColor]];
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        Cart *cartObj = [appDelegate.bookmarkArray objectAtIndex:indexPath.row];
        [appDelegate removeCart:cartObj];
        [bookmarkIDArray removeObjectAtIndex:indexPath.row];
       [bookmarkTableview beginUpdates];

        [bookmarkTableview deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        //[bookmarkTableview deleteSections:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [bookmarkTableview endUpdates];
        [bookmarkTableview reloadData];
    }
    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
    }
}

Solution

  • Try removing the the following line in your code:

    [bookmarkTableview reloadData];