0
我有一些註釋我放在mapView。這工作得很好下面添加位置具體點擊功能didSelectAnnotation MapKit
float userLatitude = [[userDict objectForKey:@"lat"]floatValue];
float userLongitude = [[userDict objectForKey:@"long"]floatValue];
NSString *someString = [someArray objectAtIndex:i];
NSString *anotherString = [anotherArray objectAtIndex:i];
CLLocationCoordinate2D loopCoord = {.latitude = userLatitude, .longitude = userLongitude};
MapAnnotationViewController *addAnnotation = [[MapAnnotationViewController alloc] initWithCoordinate:loopCoord];
self.localImage = [UIImage imageNamed:@"first.png"];
[addAnnotation setTitle:someString];
[addAnnotation setSubTitle:anotherString];
[mainMapView addAnnotation:addAnnotation];
我基本上是想甚至可以添加自定義的接觸,火災時,一個人接觸到地圖上的每個標註的代碼。該方法需要從特定的位置觸發地圖(不是標準didSelect)如何標記或每個註釋傳遞一個參數去委託方法上:
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
如何獲得這樣的代碼:
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleFingerTap];
[singleFingerTap release];
//The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:[recognizer.view superview]];
//Do stuff here...
}
根據特定註釋傳遞給didSelectAnnotationView
?
你就不能訪問該didSelectAnnotationView使用view.annotation註釋? – Anna 2012-08-17 13:27:56
是的,但你會添加輕敲手勢識別器到annotationClass呢?你會怎麼做,所以它是特定於每個註釋 – Eric 2012-08-17 13:30:11
爲什麼你需要手勢識別器?委託方法將在沒有它的情況下被調用。 – Anna 2012-08-17 13:34:24