我有一个叫做“CortesViewController”的ViewController,它有一个名为myMap的MKMapView。我有一个函数showAddress,它在CortesViewController.h中定义并在相应的.m文件中实现。从另一个ViewController类调用函数
- (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按钮被带到前面。点击任何地点的名称时,我想返回到mymap,在地图中心显示选定的地点。所以我称之为“showAddress”功能
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
in 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将输入值lat,lon正确地存储在PlaceViewController.m中的UITableView中。但线
[mymap setCenterCoordinate:centerCoordinate animated:TRUE] ;
似乎没有从
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
调用时工作。
请帮忙。感谢您提前提供任何帮助。
我没有改变viewWillAppear中的方法,它完美地工作。感谢您的回答。 – alekhine