UPDATE: Tried the links you suggested, but can't get it to work.
Just to confirm I'm understanding it right, these are the steps I took.
First view controller is called FirstViewController, second is called SearchViewController.
- Import SearchViewController into FirstViewController, and add
In FirstViewController.m, add the following: SearchViewController *svc =[[SearchViewController alloc] init]; svc.delegate =self;
In SearchViewController.h I added:
@protocol SearchViewControllerDelegate
- (void)setLat:(CLLocationDegrees)lat setLon:(CLLocationDegrees) lon;
as well as the delegate property:
@property (assign) id <SearchViewControllerDelegate> delegate;
- In SearchViewController.m I synthesized delegate, and added [self.delegate setLat:51.0000 setLon:-0.10000];
From some NSLog testing it seems that the method setLatSetLon method itself is never called.
I'm currently trying to finish off my university iPad application. The purpose of it is to provide a live google/apple maps view of the campus with overlays of annotations and MKPolygons. This all works fine.
I've now added a button that loads a popover (the second view controller) with a table of the campus buildings (which are themselves objects of CampusBuilding, where the coordinates are stored) as well as a search box, and this is all fine. What I'm looking to do is when the user selects a row, the map view centres on that specific building. I've written a method below which works fine when I reference it from the maps view controller itself.
But how would I do this from the second view controller?
Here's the method that is present in the first view controller:
- (void)setLat:(CLLocationDegrees)lat setLon:(CLLocationDegrees) lon{
MKCoordinateSpan span;
span.latitudeDelta = (double) .003;
span.longitudeDelta = (double).003;
//Define the default region to focus on
MKCoordinateRegion region;
region.span=span;
region.center=CLLocationCoordinate2DMake
(lat,lon);
//set the default region to 'region'
[_mapView setRegion: region animated:YES];
[_mapView regionThatFits:region];
}
Now in the second view controller, it works fine as a table view controller. I've set it up so when the user selects a row it loads a new view. I also tried to initiate an object of the first view controller and then wrote this: FirstViewController* firstVC;
[firstVC setLat:building.latValue setLon:building.lonValue];
It all compiles but no movement happens, I assume because I'm initiating a new object, rather than referring to the one that is currently active.
Is there a way to do this? Comments on how I can improve the code are always welcome, I'm relatively new to this.
Thanks