Как отменить регистрацию объекта в управляемом объекте контекста? - PullRequest
1 голос
/ 03 апреля 2012

Есть ли способ сделать эту работу? Я не смог найти в документе.

Ответы [ 2 ]

2 голосов
/ 03 апреля 2012

Чтобы удалить объект из базы данных, используйте следующий метод:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [managedObjectContext deleteObject:[userResults objectAtIndex:indexPath.row]];
    [userResults removeObjectAtIndex:indexPath.row];
    // Save the context.
    NSError *error = nil;
    if (![managedObjectContext save:&error]) {
    /*
     Replace this implementation with code to handle the error appropriately.

     abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
     */
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}
[self.tableView reloadData];

}

Где userResults - это тип NSMutableArray, который используется для выборки данных и хранения временных значений

0 голосов
/ 03 апреля 2012

Если вы имеете в виду удаление, вы можете использовать [context deleteObject:object], где context - ваш NSManagedContext, а object - ваш NSManagedObject производный объект.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...