title: Edit CoreData values
body: <p>I've been trying to pass some data from a tableview to an editviewcontroller,to be able to edit it and save it, but I haven't been lucky</p>
  
  <p>I don't know how to pass those values from the selected row to an editview and then save the new values</p>
  
  <p>here is my code:</p>
  
  <pre><code>- (NSManagedObjectContext *)managedObjectContext{
  NSManagedObjectContext *context = nil;
  id delegate = [[UIApplication sharedApplication] delegate];
  if ([delegate performSelector:@selector(managedObjectContext)]) {
      context = [delegate managedObjectContext];
  }
  return context;
  }
  -(IBAction)atras:(id)sender{
  MenuViewController *m=[[MenuViewController alloc] initWithNibName:nil bundle:nil];
  [self presentViewController:m animated:YES completion:nil];
  
  }
  -(IBAction)guardar:(id)sender{
  NuevaTareaViewController *n=[[NuevaTareaViewController alloc] initWithNibName:nil bundle:nil];
  [self presentViewController:n animated:YES completion:nil];
  
  }
  - (void)viewDidAppear:(BOOL)animated
  {
  [super viewDidAppear:animated];
  
  // Fetch the devices from persistent data store
  NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
  NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Tareas"];
  self.tareas = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
  
  [tableView reloadData];
  }
  
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
  // Return the number of sections.
  return 1;
  }
  
   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
  // Return the number of rows in the section.
  return self.tareas.count;
  }
  
   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  static NSString *CellIdentifier = @"Cell";
  UITableViewCell *cell;
  
  cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
  }
  
  
  // Configure the cell...
  NSManagedObject *materia = [self.tareas objectAtIndex:indexPath.row];
  [cell.textLabel setText:[NSString stringWithFormat:@"%@", [materia valueForKey:@"nombre"]]];
  cell.textLabel.textColor=[UIColor whiteColor];
  cell.textLabel.font=[UIFont fontWithName:@"Chalkduster" size:(16)];
  
  NSString *detalle=[NSString stringWithFormat:@"%@: Toca para ver los Detalles",[materia valueForKey:@"materia"]];
  [cell.detailTextLabel setText:detalle];
  cell.detailTextLabel.textColor=[UIColor whiteColor];
  cell.detailTextLabel.font=[UIFont fontWithName:@"Chalkduster" size:(12)];
  
  return cell;
  }
  - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  {
  // Return NO if you do not want the specified item to be editable.
  return YES;
  }
  
  
   - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  {
  NSManagedObjectContext *context = [self managedObjectContext];
  
  if (editingStyle == UITableViewCellEditingStyleDelete) {
      // Delete object from database
      [context deleteObject:[self.tareas objectAtIndex:indexPath.row]];
  
      NSError *error = nil;
      if (![context save:&amp;error]) {
          NSLog(@"Can't Delete! %@ %@", error, [error localizedDescription]);
          return;
      }
  
      // Remove device from table view
      [self.tareas removeObjectAtIndex:indexPath.row];
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  }
  }
  - (void)viewDidLoad
  {
  [super viewDidLoad];
  
  // Uncomment the following line to preserve selection between presentations.
  // self.clearsSelectionOnViewWillAppear = NO;
  
  // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  // self.navigationItem.rightBarButtonItem = self.editButtonItem;
  }
  
   - (void)didReceiveMemoryWarning
  {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
  }
   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  
  NSManagedObject *materia = [self.tareas objectAtIndex:indexPath.row];
  
  NSString *perfil_activo = [materia valueForKey:@"descripcion"];
  NSUserDefaults *defs=[NSUserDefaults standardUserDefaults];
  //[defs setObject:perfil_activo forKey:@"perfil_activo"];
  
  [tableView deselectRowAtIndexPath:indexPath animated:YES];
  
  UIAlertView *a=[[UIAlertView alloc] initWithTitle:@"texto" message:perfil_activo delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
  [a show];
  
  }
  </code></pre>
  
  <p>Thanks
  Santiago</p>