简体   繁体   English

核心数据删除对象

[英]Core data delete objects

I use core data in my application. 我在应用程序中使用核心数据。 When I delete object with [context deleteObject:obj] , object is not deleted only with empty fields. 当我使用[context deleteObject:obj]删除对象时,对象不会仅使用空字段删除。 How can I delete object permanently? 如何永久删除对象? Thanks in advanced. 提前致谢。 I use table view and when this view is filled with data from core data, there are empty rows where were deleted objects. 我使用表视图,当该视图中填充了核心数据中的数据时,有空行被删除了。 This is the code: 这是代码:

LNAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
self.context = [appDelegate managedObjectContext];
self.accounts = [[NSArray alloc] init];

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription 
                               entityForName:@"Accounts" inManagedObjectContext:self.context];
[fetchRequest setEntity:entity];
NSError *error;

self.accounts = [self.context executeFetchRequest:fetchRequest error:&error];

Are you making sure to save the context after you make the change? 更改后确定要保存上下文吗?

NSError *error = nil;
if(![self.managedObjectContext save:&error])
{
  /*
   //Handle error
  */
  NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}

Also make sure that you are referencing the correct context, as you can have more than one. 另外,请确保您引用的是正确的上下文,因为可以有多个上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM