title: Open edit view controller from table view using core data
body: <p>In my iOS app I am using Core Data to show data on a table view. On the same view I have included an add button, which opens a new view controller where I can add a new record.</p>
  
  <p>From this view I return to the table view and the new added record is shown correctly. Now, what I want to do is to select a row on the table view and open a new view controller to edit the fields of the record. The edit view controller name is <code>EditViewController</code>. Here is my table view controller source, so yo can please explain me the method to implement to pass the selected row record to the edit view controller, so I can later edit and save the information.
  I have seen some examples for that question regarding the <code>didSelectedRowAtIndexPath</code> method, but all based on a storyboard, which I am not using in my project.</p>
  
  <pre><code>#import "RootViewController.h"
  #import "AddToDoViewController.h"
  
  
  @interface RootViewController ()
  - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
  @end
  
  
  @implementation RootViewController
  
  @synthesize fetchedResultsController, managedObjectContext,AddToDoButton;
  
  
  #pragma mark -
  #pragma mark View lifecycle
  
  - (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"Today"];
    [[self navigationItem] setRightBarButtonItem:[self editButtonItem]];
  
  
  
  
  
    NSError *error = nil;
    if (![[self fetchedResultsController] performFetch:&amp;error])
    {
      NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
      abort();
    }
  }
  - (void) viewWillAppear:(BOOL)animated{
      NSError *error = nil;
      if (![[self fetchedResultsController] performFetch:&amp;error])
      {
          NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
          abort();
      }
      [self.tableView reloadData];
  }
  - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
  {
    NSManagedObject *managedObject = [fetchedResultsController objectAtIndexPath:indexPath];
    [[cell textLabel] setText:[[managedObject valueForKey:@"thingName"] description]];
    [[cell detailTextLabel] setText:[[managedObject valueForKey:@"thingDescription"] description]];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
      cell.textLabel.textColor = [UIColor blueColor];
      cell.textLabel.font = [UIFont fontWithName:@"Noteworthy" size:16.0f];
      cell.detailTextLabel.font = [UIFont fontWithName:@"Noteworthy" size:14.0f];
  }
  
  #pragma mark -
  #pragma mark Table view data source
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
    return [[fetchedResultsController sections] count];
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
    id &lt;NSFetchedResultsSectionInfo&gt; sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
    static NSString *CellIdentifier = @"Cell";
  
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                     reuseIdentifier:@"Cell"] autorelease];
    }
  
    [self configureCell:cell atIndexPath:indexPath];
  
    return cell;
  }
  
  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  {
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
      NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
      [context deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]];
  
      NSError *error = nil;
      if (![context save:&amp;error])
      {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
      }
    }   
  }
  
  - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  {
    return YES;
  }
  
  - (void)tableView:(UITableView *)tableView 
  moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath 
        toIndexPath:(NSIndexPath *)destinationIndexPath;
  {  
    NSMutableArray *things = [[fetchedResultsController fetchedObjects] mutableCopy];
  
    // Grab the item we're moving.
    NSManagedObject *thing = [[self fetchedResultsController] objectAtIndexPath:sourceIndexPath];
  
    // Remove the object we're moving from the array.
    [things removeObject:thing];
    // Now re-insert it at the destination.
    [things insertObject:thing atIndex:[destinationIndexPath row]];
  
    // All of the objects are now in their correct order. Update each
    // object's displayOrder field by iterating through the array.
    int i = 0;
    for (NSManagedObject *mo in things)
    {
      [mo setValue:[NSNumber numberWithInt:i++] forKey:@"displayOrder"];
    }
  
    [things release], things = nil;
  
    [managedObjectContext save:nil];
  }
  
  
  
  
  
  
  #pragma mark -
  #pragma mark Fetched results controller
  - (IBAction)AddToDoAction:(id)sender {
  
      AddToDoViewController *viewController = [[AddToDoViewController alloc] init];
      [self presentViewController:viewController animated:YES completion:nil];
  
  }
  
  - (NSFetchedResultsController *)fetchedResultsController
  {
    if (fetchedResultsController) return fetchedResultsController;
  
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = 
                 [NSEntityDescription entityForName:@"FavoriteThing" 
                             inManagedObjectContext:managedObjectContext];
  
    [fetchRequest setEntity:entity];
  
    NSSortDescriptor *sortDescriptor = 
                [[NSSortDescriptor alloc] initWithKey:@"displayOrder" 
                                            ascending:YES];
  
    NSArray *sortDescriptors = [[NSArray alloc] 
                                initWithObjects:sortDescriptor, nil];  
    [fetchRequest setSortDescriptors:sortDescriptors];
  
    NSFetchedResultsController *aFetchedResultsController = 
                [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
                                                    managedObjectContext:managedObjectContext
                                                      sectionNameKeyPath:nil cacheName:@"ThingsCache"];
    aFetchedResultsController.delegate = self;
    [self setFetchedResultsController:aFetchedResultsController];
  
    [aFetchedResultsController release];
    [fetchRequest release];
    [sortDescriptor release];
    [sortDescriptors release];
  
    return fetchedResultsController;
  }    
  
  - (void)dealloc {
    [fetchedResultsController release];
    [managedObjectContext release];
  
  
    [super dealloc];
  }
  
  
  @end
  </code></pre>
  
  <p>Hi again. I have done following after the answer from @flexaddicted:
  I have add following code to my EditToDoViewController.h file at the interface block:</p>
  
  <pre><code>NSManagedObject *selectedObject;
  </code></pre>
  
  <p>And also following declaration:</p>
  
  <pre><code>@property (nonatomic, retain) NSManagedObject *selectedObject;
  </code></pre>
  
  <p>And in my EditToDoViewController.m file i have added following code:</p>
  
  <pre><code>@synthesize selectedObject;
  </code></pre>
  
  <p>The didSelectRowAtIndexPath method changed to:</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  
  
      EditToDoViewController *detailViewController = [[EditToDoViewController alloc] initWithNibName:@"EditToDoViewController" bundle:nil];
      NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
      EditToDoViewController.selectedObject = selectedObject;
  
  }
  </code></pre>
  
  <p>But at this point I am receiving this error message:
   Property 'selectedObject' not found on object of type 'EditToDoViewController'</p>
  
  <p>I think I have well declared the property 'selectedObject', I don't understand the error....
  Thank you</p>