【发布时间】:2014-01-02 15:54:11
【问题描述】:
我想在我的地图上创建自定义标注。我现在已经试过了-
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
NSLog(@"ANNNOTATION VIEW : %@", view);
NSLog(@"VIEW ANNOTATION: %@", view.annotation);
MyMapAnnotationViewController* mapAnnotationViewController = [[MyMapAnnotationViewController alloc]initWithNibName:@"MapAnnotationView" bundle:nil];
MyLocation* location = (MyLocation*)view.annotation;
[mapAnnotationViewController setTitle: [location title]];
[mapAnnotationViewController setRating:3.0];
[view addSubview:mapAnnotationViewController.view];
}
-(void)viewWillAppear:(BOOL)animated{
[_mapView setRegion: _viewRegion];
for (id<MKAnnotation> annotation in _mapView.annotations) {
[_mapView removeAnnotation:annotation];
}
for(NSDictionary* result in _resultsToPlot){
NSString* address = someAddr;
NSString* restaurantTitle = someTitle;
NSString* description = someDescription;
NSString* lonLat = someLonLat;
NSArray *list = [lonLat componentsSeparatedByString:@";"];
CLLocationCoordinate2D coordinate;
coordinate.longitude = [[list objectAtIndex: 1] doubleValue];
coordinate.latitude = [[list objectAtIndex: 0] doubleValue];
MyLocation *annotation = [[MyLocation alloc] initWithName:restaurantTitle address:address coordinate:coordinate] ;
[_mapView addAnnotation:annotation];
}
MyLocation 是 MKAnnotation 的子类。
但是,当我单击时,这就是现在的样子 -
因此,当我单击一个图钉时,我的自定义视图会显示并且注释会显示。我只想显示自定义视图。此外,当我单击另一个图钉时,之前的自定义视图仍然存在。
我如何获得它以便注释成为我的自定义视图?
好的-所以我做了以下并添加了这个-
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(MKAnnotationView*)annotation{
annotation.canShowCallout = NO;
return annotation;
}
我现在收到此错误-
NSInvalidArgumentException', reason: '-[MyLocation setCanShowCallout:]: unrecognized selector sent to instance 0xcb683e0'
【问题讨论】:
标签: ios cocoa-touch mkmapview mkannotationview