지도에서 테이블의 선택 항목을 볼 수있게 해주는 iPhone 용 탐색 기반 응용 프로그램이 있습니다. 지도에서 사용자가 선택한 위치를 정확히 찾아내는 주석이 있습니다. 정상적인 동작에 따라 사용자가 주석을 클릭하면 콜 아웃에 위치에 대한 세부 정보가 나타납니다. 여기에 문제 없습니다.지도가 처음로드 될 때 자동으로지도에서 주석의 콜 아웃을 여는 방법은 무엇입니까?
제 질문은 사용자가지도가 포함 된 화면으로 이동하면 주석이 자동으로 표시되도록하고 싶습니다. 사용자가지도를 보려면 주석을 클릭 할 필요가 없습니다. 위치에 대한 세부 정보가 있지만이 작업을 수행하는 방법을 잘 모르겠습니다.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Restaurant *rLocation = [restaurantList objectAtIndex:indexPath.row];
MapViewController *mapController = [[MapViewController alloc] initWithRestaurant:rLocation];
[self.navigationController pushViewController:mapController animated:YES];
[mapController release];
}
다음 MapViewController 이전 화면에서 다음의 방법에서 호출
- (void)viewDidLoad {
[super viewDidLoad];
MKCoordinateRegion region;
MKCoordinateSpan span;
NavButtonAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
userCoord = delegate.userLocation.coordinate;
region.center = userCoord;
span.latitudeDelta = 0.4;
span.longitudeDelta = 0.4;
region.span = span;
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.showsUserLocation = YES;
[mapView setRegion:region animated:YES];
RestaurantAnnotation *rAnnotation = [[RestaurantAnnotation alloc] init];
rAnnotation.title = restaurantObj.name;
rAnnotation.subtitle = restaurantObj.address;
rAnnotation.subtitle = [restaurantObj.address stringByAppendingFormat:@" %@", restaurantObj.hours];
rAnnotation.subtitle = [restaurantObj.address stringByAppendingFormat:@" %@", restaurantObj.phoneNumber];
CLLocationCoordinate2D newCoord = {restaurantObj.latitude, restaurantObj.longitude};
rAnnotation.coordinate = newCoord;
[mapView addAnnotation:rAnnotation];
}
: 나는지도 표시 대부분의 작업이 수행 내 "MapViewController"클래스에 다음과 같은 방법을 이 작업을 수행하려면 다음 방법을 사용해야한다는 것을 알고 있습니다.
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
id<MKAnnotation> myAnnotation = [mapView.annotations objectAtIndex:0];
[mapView selectAnnotation:myAnnotation animated:YES];
}
그러나 나는 잘 모르겠습니다. 나는 한 번에 모두 사용하고있는 많은 주석을 가지고 있지 않다. 나는이 주석과 함께 작업 할 필요가있는 하나의 주석만을 가지고있다.
어디에서이 방법을 응용 프로그램에 넣을 수 있습니까? 어디에서 호출해야합니까?
viewDidLoad 메서드에서이 메서드를 호출하고 실제 메서드를 내 MapViewController 클래스에 넣을 수 있습니까?
신속한 답장을 보내 주셔서 감사합니다. 그러면 viewDidLoad 메서드에서 메서드를 호출할까요? – syedfa
아니요, 직접 호출 할 필요는 없습니다. 델리게이트를 설정하는 한 mapview에 의해 자동으로 호출됩니다. – benwong
답변 해 주셔서 대단히 감사합니다. 당신의 솔루션은 효과가있었습니다! 조심해. – syedfa