title: Custom table cells to control map view
body: <p>I have one view controller which contains a mapView and tableView (pictured below). I was wondering if it was possible to click on a table cell and the mapView region would update with its coordinates? I have tried many methods, the main one which seemed promising:</p>
  
  <p>HorizontalTableCell.m</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
  NSDictionary *currentSelected = [_articles objectAtIndex:indexPath.row];
  
  HomeViewController *mvc = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
  
  CLLocationCoordinate2D location;
  location.latitude = [[currentSelected objectForKey:@"lat"] doubleValue];
  location.longitude = [[currentSelected objectForKey:@"long"] doubleValue];
  
  MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 1.5*METERS_PER_MILE, 1.5*METERS_PER_MILE);
  
  [mvc.mapView setRegion:region];
  
  //testing, shows which table cell is selected
  NSString *msg = [NSString stringWithFormat:@"%f %f", location.latitude, location.longitude];
  UIAlertView *messageAlert = [[UIAlertView alloc] initWithTitle:@"Row Selected" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
  
  // Display Alert Message
  [messageAlert show];
  
  }
  </code></pre>
  
  <p>The tableView is using a custom table cell, so this method is in its own HorizontalTableCell class (while the mapView is in the HomeViewController class). Selecting a cell works, because the alert gives me the correct coordinates for the selected cell (which grabs the lat and long from an array _articles), but for some reason I can't access or control my mapView in the Home View Controller.</p>
  
  <p><img src="https://i.stack.imgur.com/ruJGL.png" alt="My view controller in question">
  The other way I tried was calling a Home View Controller method in the Horizontal Table Cell's didSelectRowAtIndexPath:</p>
  
  <p>HomeViewController.h</p>
  
  <pre><code>- (void)changeMapRegion:(CLLocationCoordinate2D *)coord;
  </code></pre>
  
  <p>HomeViewController.m</p>
  
  <pre><code>- (void)changeMapRegion:(CLLocationCoordinate2D)coord {
      MKCoordinateRegion newRegion = MKCoordinateRegionMakeWithDistance (coord, 1.5*METERS_PER_MILE, 1.5*METERS_PER_MILE);
  
      NSLog(@"the coordinates are %f and %f", coord.latitude, coord.longitude);
  
      [_mapView setRegion:newRegion animated:YES];
  
  }
  </code></pre>
  
  <p>In the HorizontalTableCell.m</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      NSDictionary *currentSelected = [_articles objectAtIndex:indexPath.row];
  
      HomeViewController *mvc = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
  
      CLLocationCoordinate2D location;
      location.latitude = [[currentSelected objectForKey:@"lat"] doubleValue];
      location.longitude = [[currentSelected objectForKey:@"long"] doubleValue];
  
      [mvc changeMapRegion:location];
  }
  </code></pre>
  
  <p>When I click on a table cell, the log gives me the correct coordinates, so I am calling the method fine, but the mapView doesn't change its region.. I'm totally stuck! I would love some advice.</p>