Hi Guys,
In my app, I want to delete particular row from table view. Table view contents are coming from database and after getting data from database then I pushed to array. Then I reversed an array, Here after I am displaying content in table view. My problem is that when I am trying to delete the second row of table view on behalf of second row it delete first row of table view. Here I put inside commitEditingStyle method code,
if (editingStyle == UITableViewCellEditingStyleDelete) {
[savedArray removeObjectAtIndex:indexPath.row];
[saveTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:[savedArray objectAtIndex:val]] withRowAnimation:UITableViewRowAnimationFade];
newsObj = [(BlackSheepAppDelegate *)[[UIApplication sharedApplication] delegate] nsManagedObjectContext];
NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription * entity = [NSEntityDescription entityForName:@"ArticalDetails" inManagedObjectContext:self.newsObj];
[fetchRequest setEntity:entity];
NSError *error;
NSArray *items = [self.newsObj executeFetchRequest:fetchRequest error:&error];
[newsObj deleteObject:[items objectAtIndex:indexPath.row]];
NSLog(@"Deleted content position %d", indexPath.row);
if ([newsObj hasChanges] && ![newsObj save:&error]) {
NSLog(@"%@", [error description]);
}
[saveTable reloadData];
}
for reverse an array,
for(int i = 0; i < [savedArray count] / 2; i++) {
int j = [savedArray count] - i - 1;
id temp = [[savedArray objectAtIndex:i] retain];
[savedArray replaceObjectAtIndex:i withObject:[savedArray objectAtIndex:j]];
[savedArray replaceObjectAtIndex:j withObject:temp];
[temp release];
}
Please help me out!