Я не могу понять, как удалить из базы данных. Он только обновляет массив, но не базу данных.
Беглец - это лицо. Я как-то должен объявить беглеца через управляемый объектный текст ... Я думаю?
Я, наверное, слишком устал, чтобы понять это так ...
@synthesize managedObjectContext, fetchedResultsController;
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
iBountyHunterAppDelegate *appDelegate = (iBountyHunterAppDelegate*)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *managedObjectContexta = appDelegate.managedObjectContext;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Fugitive" inManagedObjectContext:managedObjectContexta];
[request setEntity:entity];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:NO];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
NSError *error;
NSMutableArray *mutableFetchResults = [[managedObjectContexta executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error;
}
self.items = mutableFetchResults;
[mutableFetchResults release];
[request release];
[self.tableView reloadData];
}
// Configure the cell...
Fugitive *fugitive = [items_ objectAtIndex:indexPath.row];
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the managed object at the given index path.
Fugitive *fugitive = [items_ objectAtIndex:indexPath.row];
[managedObjectContext deleteObject:fugitive];
// Update the array and table view.
[items_ removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
// Commit the change.
NSError *error = nil;
if (![managedObjectContext save:&error]) {
// Handle the error.
}
}}