2012-03-04 65 views
0

這已經快把我逼瘋了試圖弄清楚這一點...核心數據 - 更新持久性存儲不工作

我有一個管理對象,我需要設置標誌屬性的記錄是一個最喜歡的

的問題是,我沒有看到保存到數據庫中的值(我已經從模擬器拉數據庫,並檢查它???)

以下是代碼片段...注意沒有錯誤從保存中丟棄

// Tell the user we have added to favorites 

NSString *yes = @"Y"; 

[cardMessage setValue:yes forKey:@"favorite"]; 

NSError *error = nil; 
BOOL savedSuccessfully = [managedObjectContext save:&error]; 
if (!savedSuccessfully) 
{ 
    /* 
    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. 
    */ 
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
    abort(); 
} 

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
     message:@"Message added to Favorites" delegate:self 
     cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[alert show]; 

回答

0

您可以使用SQLite Manager(瀏覽器插件)查看模擬器數據庫中的數據 - 快速且簡單(Firefox插件)。 https://code.google.com/p/sqlite-manager/ 使用 - (BOOL)hasChanges - 萬一出現意外出錯(例如沒有變化)。

+0

我已經在使用Firefox插件來查看數據...因此,爲什麼更新沒有反映的混亂 – rs2000 2012-03-04 14:48:01

+0

我添加了以下內容來記錄是否發生了更改... NSLog(@「Before Save ...更改=%@ \ n「,([managedObjectContext hasChanges]?@」YES「:@」NO「)); - 結果是沒有! ......之後對受管理對象進行更新......我想我可能會越來越近......謝謝 – rs2000 2012-03-04 15:07:30

+0

這仍然讓我瘋狂......一些基本的錯誤....我現在寫了一些邏輯重新讀取記錄,然後更新參數...所有的代碼工作,但不會將數據保存到數據庫...以下是代碼 – rs2000 2012-03-04 18:45:17

相關問題