my app is based on core data using magical record.
In one of my tabelView with custom cell the user can see all his records and tap a button to add it to favorites ( basically changing a value of one string for the selected item).
after that i change the button image to give a feedback to the user.
This works, but sometimes the app crash (not always), and xcode doesn't output any error.
here my code for IBAction:
[[DataManager sharedClass] setFavorite:@"Sono un preferito" ofContactInCell:[sender tag]];
UIButton *myButton = (UIButton *)sender;
[myButton setImage:[UIImage imageNamed:@"AddPreferito"] forState:UIControlStateNormal];
and the method to change the value of the string:
-(void) setFavorite:(NSString*)setPreferito ofContactInCell:(int)cell
{
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
NSArray* arra = [Ricetta MR_findAllSortedBy:@"nome" ascending:YES];
Ricetta* personaTrovata = arra[cella];
personaTrovata.preferito = setPreferito;
[localContext MR_saveToPersistentStoreAndWait];
[self.delegate ricaricaLaTable];
}
I think that the problem is in the image switching, but maybe I'm wrong. Help!