I want to reload(refresh) my mainviewcontroller after changes. I add some data to data model and after save operation I put buttons to data elements on my main view. In second controller I make a edition section in which I change or delate data from base. My question is: How can I reload main view after delating element from base. My code for creating buttons is in mainviewcontroller:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Destination" inManagedObjectContext:_managedObjectContext];
[request setEntity:entity];
NSError *error = nil;
mutableFetchResults = [[_managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
CGFloat y = 130.;
for (int i = 0; i < [mutableFetchResults count]; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"ikonki%d.png",i]] forState:UIControlStateNormal];
[button setTitle:@"Test" forState:UIControlStateNormal];
NSLog(@"%@",_destination3.nazwa);
[button setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];
[button setEnabled:YES];
[button addTarget:self
action:@selector(buttonHandler:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
button.frame = CGRectMake(x, y, 64 , 64);
Do you know
NSFetchedResultsController? Go to documentation and look at DataSectionTitles and iPhoneCoreDataRecipes samples. Here you can find how to use this class. Basically this class gets your fetch request, listens for changes and if you delete / insert / update / … objects in yourNSManagedObjectContextit triggers delegate methods where you can update your view.