我有一個地圖視圖,並且有10個存儲位置數據通過webservice傳遞。我只想推入我的詳細視圖以顯示點擊商店的地址,電話和其他信息。當在地圖上點擊註解時將數據傳遞到detailView
當用戶點擊或觸摸mapkit上的註釋時,我需要將數據傳遞給我的detailview
。我的mapview
中有10個註釋,首先我想知道,我該如何理解或如何獲得單擊註釋的註釋ID?
這是我的方法返回引腳
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]]) return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorPurple;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
return pinView;
}
/* and my action method for clicked or tapped annotation: */
- (IBAction)showDetails:(id)sender{
NSLog(@"Annotation Click");
[[mtMap selectedAnnotations]objectAtIndex:0];
magazaDetayViewController *detail = [[magazaDetayViewController
alloc]initWithNibName:@"magazaDetayViewController" bundle:nil];
[email protected]"";
[email protected]"";
[email protected]"";
[email protected]"";
[email protected]"";
[self.navigationController pushViewController:detail animated:YES];
}
如果我可以獲取單擊註解索引沒有我可以用我的陣列填寫詳細屬性。 如果這是不可能的有沒有其他的方式來做到這一點?
Thnx詳細答案我有一個問題:哪裏以及我如何填寫或設置annView.address? – ercan
你如何在地圖上獲得註釋? – superGokuN
在我的viewdidload方法 for(int i = 0; i <[arrLat count]; i ++) {CLLocationCoordinate2D theCoordinate1; konumpin * myAnnotation1 = [[konumpin alloc] init]; theCoordinate1.latitude = [[arrLong objectAtIndex:i] doubleValue]; theCoordinate1.longitude = [[arrLat objectAtIndex:i] doubleValue]; myAnnotation1.coordinate = theCoordinate1; myAnnotation1。title = [arrMagaza objectAtIndex:i]; [annotations addObject:myAnnotation1]; } [mtMap addAnnotations:annotations]; – ercan