0

I am using a UITableViewController inside of a UINavigationController for my Master and I'm using a UIViewController implementing the GMSMapViewDelegate inside of a UINavigationController for my detail side to display a google map. Currently the table view and the Google map are displaying in the UISplitViewController fine.

I am a beginner who recently finished reading Programming in Objective C and Big Nerd Ranch's guide for IOS 7. I can't figure out how to use the didSelectRowAtIndexPath method to change the camera position with the map. I know how to change the camera position, I've wrote NSLog calls to test whether my app was responding when tapping a particular row, but I can't figure out how to connect the two controllers. I thought about trying to make the controller holding the mapview a delegate for the UITableView, but I am confused as to how to connect the two. What options do I have to carry something like that out.

This is what my appdelegate file looks like.

...
mapviewController *mvc = [[mapViewController alloc]init];
locationTableController *ltc = [[locationTableController alloc]init];

UISplitViewController *svc = [[UISplitViewController alloc]init];
UINavigationController *sideNav = [[UINavigationController alloc]initWithRootViewController:ltc];
UINavigationController *mapNav = [[UINavigationController alloc]initWithRootViewController:mvc];
svc.delegate = mapNav;
svc.viewControllers = @[sideNav,mapNav];
....
Abdullah Rasheed
  • 3,562
  • 4
  • 33
  • 51

1 Answers1

1

I would keep your locationTableController as delegate and datasource for the table. You can use self.splitViewController to access the splitViewController, your mapNav is then at viewControllers[1] and your mapviewcontroller is rootViewController of mapNav. If you implement a changeCameraPosition method in your mapviewcontroller, you can call this from within didSelectRowAtIndexPath. So in didSelectRowAtIndexPath:

UISplitViewController *svc = self.splitViewController;
UINavigationController *mapNav = svc.viewControllers[1];
mapViewController *mvc = (mapViewController *)mapNav.rootViewController;
[mvc changeCameraPosition];

You may need to import the relevant .h files if not already done. Personally I would add some properties to the splitViewController to speed up accessing the other view controllers.

pbasdf
  • 21,386
  • 4
  • 43
  • 75
  • Excellent. Being a beginner, I didn't know that if a reciever is a child of a split view controller there was a property "splitViewController" that would return the nearest ancestor in the view controller hierarchy. The only difference is I used topViewController once I had access to the mapNav UINavigationController. – Abdullah Rasheed Sep 22 '14 at 15:22