【问题标题】:managedObjectContext deleteObject:matches not deleting data from Core data base?managedObjectContext deleteObject:匹配不从核心数据库中删除数据?
【发布时间】:2012-08-09 09:42:27
【问题描述】:

我试图从 ios 应用程序的核心数据库中删除行但它不起作用,

if (editingStyle == UITableViewCellEditingStyleDelete) {

     appDelegate = [[UIApplication sharedApplication] delegate];   
        NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"PRODUCTTABLE" inManagedObjectContext:appDelegate.managedObjectContext];        
        NSFetchRequest *request = [[NSFetchRequest alloc] init];        
        [request setEntity:entityDesc];        
        NSError *error; 
        NSManagedObject *matches = nil;
        NSArray *objects = [appDelegate.managedObjectContext executeFetchRequest:request error:&error];
        NSLog(@"Array Count....%d",[objects count]);
        matches=[objects objectAtIndex:([indexPath row])];
        NSLog(@"...%@",[matches valueForKey:@"productID"]);
        NSLog(@"...%@",[matches valueForKey:@"pName"]);
        NSLog(@"...%@",[matches valueForKey:@"pPrice"]);
        NSLog(@"...%@",[matches valueForKey:@"pDate"]);           
        [appDelegate.managedObjectContext deleteObject:matches];


    }   

以下代码的o/p:

Array Count....12
...ABC1226
...ABC-005
...599.39
...2012-08-09 05:07:50 +0000

我正在从具有相同 NSManagedObject 的核心数据中获取数据。为什么删除不更新核心数据?

【问题讨论】:

  • 您必须实际保存才能保留您的更改。 - (BOOL)save:(NSError **)error.

标签: iphone ios core-data nsmanagedobjectcontext


【解决方案1】:

更改后保存上下文。

NSError * error = nil;
[appDelegate.managedObjectContext deleteObject:matches];
[appDelegate.managedObjectContext save:&error];

【讨论】:

    猜你喜欢
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    • 2018-06-21
    • 2017-03-20
    相关资源
    最近更新 更多