【问题标题】:Core data delete objects核心数据删除对象
【发布时间】:2012-01-03 23:28:22
【问题描述】:

我在我的应用程序中使用核心数据。当我用[context deleteObject:obj] 删除对象时,对象不会只删除空字段。如何永久删除对象?提前致谢。我使用表格视图,当这个视图填充了核心数据中的数据时,有空行被删除了对象。这是代码:

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];

【问题讨论】:

  • 什么意思,只有空字段?您使用哪种 UI 来显示这些对象?这里需要更多信息。
  • 您是否使用获取的结果控制器来处理表格视图的填充/更新?
  • @PhilippeSabourin 你可以在我的帖子中看到代码

标签: ios core-data ios4 ios5


【解决方案1】:

您是否确保在进行更改后保存上下文?

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

还要确保您引用了正确的上下文,因为您可以拥有多个上下文。

【讨论】:

  • 当你删除时你是在使用 self.context 还是仅仅使用 context?
猜你喜欢
  • 2016-10-27
  • 2012-06-17
  • 2016-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-21
相关资源
最近更新 更多