2015-11-02 93 views
-1

我正在構建一個配方應用程序,該應用程序可以保存包含圖像和標題的配方。標題字符串和圖像一樣可以很好地保存,但是當我將標題從核心數據中拉出時,標籤文本就會如此顯示。非常奇怪的核心數據錯誤iOS

enter image description here

它保存爲核心的數據串,這裏是哪裏保存和檢索它的方法。

保存

- (void)saveRecipe { 

[[RecipeController sharedInstance]addRecipeWithTitle:self.titleField.text description:self.descriptionField.text andImage:self.chosenImage]; 

[[NSNotificationCenter defaultCenter]postNotificationName:@"recipeSaved" object:nil]; 

[self refreshTableViewData]; 
} 

檢索

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 

Recipe *recipe = [RecipeController sharedInstance].recipes[indexPath.section]; 

cell.recipeImageView.image = [UIImage imageWithData:recipe.picture]; 
cell.descriptionLabel.text = recipe.description; 
cell.titleLabel.text = recipe.title; 

return cell; 

} 

問題二號......

這只是開始發生,是工作了一段時間正常,但在細節VC當我保存第二個條目具有不同的標題,它只是用相同的條目填充表格視圖(它在表格視圖中被複制);但是當我選擇它時,細節VC up日期與正確的條目!

enter image description here

然而,當我刪除了第一個它顯示了從之前正確的條目。

enter image description here

enter image description here

下面是代碼,我更新的詳細VC,並得到正確的入口......

- (void)updateWithRecipe:(Recipe *)recipe { 

self.recipe = recipe; 
self.imageView.image = [UIImage imageWithData:recipe.picture]; 
self.titleField.text = recipe.title; 
self.descriptionField.text = recipe.description; 

} 

在VC的SEGUE方法...(這作品,傳遞正確的條目,但它不會在桌面視圖上顯示)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

DetailViewController *detailViewController = [DetailViewController new]; 

    detailViewController.recipe = [RecipeController sharedInstance].recipes[indexPath.row]; 

[self.navigationController pushViewController:detailViewController animated:YES]; 
    } 

我已經刪除了我的手機上的應用程序,並再次運行它,但這種情況繼續發生?任何幫助將不勝感激!

回答

2

description是由NSObject提供的方法,其給出了對象的描述。不要給你的核心數據字段相同的名稱。編輯應該已經警告過你。 addRecipeWithTitle: description:...實際存儲該參數的字段是哪一個?

+0

好的,這很有道理,我修正了那個錯誤,但是另一個呢?謝謝您的幫助! – Echizzle

+0

您是否可以添加足夠的項目,以便您可以執行大滾動來區分單元緩存錯誤和Core Data對象標識錯誤? – Tommy