【问题标题】:callout is not showing by default in map标注在地图中默认不显示
【发布时间】:2013-06-28 09:48:55
【问题描述】:

我试图通过不点击图钉来在图钉上显示标注。简而言之,我想在图钉放置在地图上时显示标注。

这是我正在使用的代码:

-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation         //  Method to handle all the annotations on map.
{

    if([annotation isKindOfClass: [MKUserLocation class]])
        return nil;

    static NSString *annotationID = @"MyAnnotation";

    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationID] ;

    if (!pinView) {
        pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationID];
        pinView.canShowCallout = YES;
        pinView.image = [UIImage imageNamed:@"map_pin.png"];

        //Setting Right call button
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

        //Setting Left Call button
        self.favButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.favButton.frame = CGRectMake(0, 0, 23, 23);
        self.favButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        self.favButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [self.favButton setImage:[UIImage imageNamed:@"favourite.png"] forState:UIControlStateNormal];
        pinView.leftCalloutAccessoryView = self.favButton;

        [self.mapView selectAnnotation:annotation animated:YES];
    }
    return pinView;

}

任何帮助都将不胜感激。

【问题讨论】:

    标签: ios map annotations callout


    【解决方案1】:

    试试这个:

    - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{
        for (id<MKAnnotation> currentAnnotation in mapView.annotations) {
            if ([currentAnnotation isEqual:annotationToSelect]) {
                [mapView selectAnnotation:currentAnnotation animated:YES];
            }
        }
    }
    

    编辑: -(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation // 处理地图上所有注解的方法。 {

    if([annotation isKindOfClass: [MKUserLocation class]])
        return nil;
    
    static NSString *annotationID = @"MyAnnotation";
    
    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationID] ;
    
    if (!pinView) {
        pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationID];
        pinView.canShowCallout = YES;
        pinView.image = [UIImage imageNamed:@"map_pin.png"];
    
        //Setting Right call button
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    
        //Setting Left Call button
        self.favButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.favButton.frame = CGRectMake(0, 0, 23, 23);
        self.favButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        self.favButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [self.favButton setImage:[UIImage imageNamed:@"favourite.png"] forState:UIControlStateNormal];
        pinView.leftCalloutAccessoryView = self.favButton;
    
                **[self performSelector:@selector(selectAnnotation:) withObject:annotation afterDelay:0.5];**
    
    }
    return pinView;
    

    }

    - (void)selectAnnotation:(id < MKAnnotation >)annotation
    {
        [self.mapView selectAnnotation:annotation animated:NO];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多