2012-01-03 113 views
0

我在我的應用程序中使用核心數據。當我用[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]; 
+0

你是什麼意思,只有空領域?你用什麼樣的UI來顯示這些對象?這裏需要更多的信息。 – 2012-01-03 23:31:30

+0

我編輯我的文章。 – 2012-01-03 23:36:47

+0

您是否使用提取的結果控制器來處理填充/更新表視圖? – 2012-01-03 23:41:02

回答

4

您是否確保在進行更改後保存上下文?

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

此外,請確保您正在引用正確的上下文,因爲您可以有多個。

+0

是的,我保存上下文 – 2012-01-03 23:54:14

+0

當你刪除你是否也使用self.context或只是上下文? – tams 2012-01-03 23:56:56

+0

我使用self.context – 2012-01-04 00:12:40