I have a ViewController called “CortesViewController” which has a MKMapView Called mymap. I have a function showAddress which is defined in CortesViewController.h and implemented in corresponding .m file.
- (void) showAddress:(float) lat :(float) lon :(int) keytype
{
centerCoordinate.latitude = lat;
centerCoordinate.longitude = lon ;
NSLog(@"with key = 0, lat lon are %f, %f", centerCoordinate.latitude, centerCoordinate.longitude);
[mymap setCenterCoordinate:centerCoordinate animated:TRUE] ;
}
I have another UitableViewController “PlacesViewController” which contains list of places with Name and Latitude and Longitude and Can be brought to front by a button placed on CortesViewController. When clicked on any place’s name I want to return to to mymap showing selected place at center of map. So I am Calling “showAddress” function
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
in PlaceViewController.m . Implementation is shown below.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Place *placeAtIndex = (Place *)[appDelegate.PlacesArray objectAtIndex:indexPath.row];
NSLog(@"required lat long is %f, %f ", placeAtIndex.PlaceLatitude, placeAtIndex.PlaceLongitude);
CortesViewController *returnToMap = [[CortesViewController alloc] init];
float tableLatitude = placeAtIndex.PlaceLatitude ;
float tableLongitude = placeAtIndex.PlaceLongitude;
[returnToMap showAddress :tableLatitude :tableLongitude : 0];
[self.navigationController dismissModalViewControllerAnimated:YES];
}
code runs without error or warning but view in mymap don’t change despite clicking on a place that has a different latitude and longitude. showAddress takes input values lat, lon correctly as stored in UITableView in PlaceViewController.m. But the line
[mymap setCenterCoordinate:centerCoordinate animated:TRUE] ;
dont seem to work when called from
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath.
Please help. Thanks for any help in advance.
It seems that you are changing some values in this line
[returnToMap showAddress :tableLatitude :tableLongitude : 0];If in showAddress you are changing view also than probably it may not reflect changes in some cases(Read details of Thread and UI component interaction in iOS).
So, I will suggest you just change variables in showAddress and apply changes in view accordingly in viewWillAppear method of CortesViewController
If above is not applicable in you case then post here so that I can understand problem in detail.