Very odd core data errors iOS

42 views Asked by At

I'm building a recipe app which saves a recipe with an image and caption. The title string saves fine as does the image but when I pull the caption out of core data, the label text appears as such.

enter image description here

It's saved as a string in core data and here are the methods where I save and retrieve it.

Save

- (void)saveRecipe {

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

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

[self refreshTableViewData];
}

Retrieve

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

}

Problem number two...

This just started happening and was working fine for a while, but in the detail VC when I save a second entry with a different title it just populates the table view with the same entry that's always been there as such (it's duplicated on the table view)... yet when I select it, the detail VC updates with the correct entry!

enter image description here

Yet when I delete the first one it shows the correct entry from before.

enter image description here

enter image description here

Here is the code where I update the detail VC and get the correct entry...

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

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

}

The segue method in the VC... (this works, passing the correct entry but it doesn't show up that way on the table view)

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

DetailViewController *detailViewController = [DetailViewController new];

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

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

I've deleted the app off my phone and ran it again but this keeps happening? Any help would be greatly appreciated!

1

There are 1 answers

2
Tommy On

description is a method provided by NSObject that gives a description of the object. Don't give your Core Data field the same name. The editor should have warned you about this. To which field is addRecipeWithTitle: description:... actually storing that parameter?