Delete row from UITableView NSMutableArray and ManagedObjectContext
I've got the UITableView which is populated from NSMutableArray. NSMutableArray was created from my NSFetchedResultsController which came from another view
Templates *template2 = (Templates *)[fetchedResultsController objectAtIndexPath:indexPath];
qModalView.templateObject = template2;
and was recorded to templateObject, so I have got all my objects in this my NSMutablArray that way.
[templateObject.questions allObjects];
Now I want to delete row in my table view , in array and in that particular object in templateObject.questions.
Please help, I have this so far:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
Questions *question_var = [questionsArray objectAtIndex:indexPath.row];
NSLog(@"_____________________________%@", question_var.question_title);
NSManagedObjectContext *context = [templateObject managedObjectContext];
[context deleteObject:[templateObject.questions objectAtIndexPath:indexPath]];
NSError *error;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo开发者_开发问答]);
abort();
}else{
NSLog(@"deleted");
}
}
You can remove the row from the table with
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:YES];
and you can delete an object from an NSMutableArray
with
[myArray removeObject:myObject];
精彩评论