У меня есть ViewController под названием «CortesViewController», который имеет MKMapView, называемое mymap. У меня есть функция showAddress, которая определена в CortesViewController.h и реализована в соответствующем файле .m.
- (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] ;
}
У меня есть другой UitableViewController "PlacesViewController", который содержит список мест с именами, широтой и долготой и может быть выведен на передний план с помощью кнопки, расположенной на CortesViewController. При нажатии на название любого места я хочу вернуться к моей карте, показывая выбранное место в центре карты. Поэтому я вызываю функцию "showAddress"
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
в PlaceViewController.m. Реализация показана ниже.
- (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];
}
код выполняется без ошибок или предупреждений, но представление в mymap не меняется, несмотря на нажатие на место, которое имеет другую широту и долготу. showAddress принимает входные значения по ширине и долготе правильно, как они хранятся в UITableView в PlaceViewController.m. Но линия
[mymap setCenterCoordinate:centerCoordinate animated:TRUE] ;
не похоже на работу при вызове с
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
.
Пожалуйста, помогите. Спасибо за любую помощь заранее.