【问题标题】:iOS - Set Detail Disclosure Button on MKAnnotationViewiOS - 在 MKAnnotationView 上设置详细信息披露按钮
【发布时间】:2012-02-21 04:41:22
【问题描述】:

我的 MapViewController 中有以下方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"];
    if (!annotationView) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapVC"];
        annotationView.canShowCallout = YES;
        annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        // could put a rightCalloutAccessoryView here
    } else {
        annotationView.annotation = annotation;
        [(UIImageView *)annotationView.leftCalloutAccessoryView setImage:nil];
    }

    return annotationView;
} 

我相信它设置正确,但是当我的地图正确显示带有标题和副标题的注释时,但它们没有显示详细信息披露按钮,我是否遗漏了什么?

另外一点是,在调试时这个方法从来没有被调用过,但是注解视图却显示了标题和副标题。

【问题讨论】:

    标签: ios uibutton mapkit mkannotation mkannotationview


    【解决方案1】:

    很可能地图视图的delegate 没有设置。

    如果没有设置delegate 或者如果你没有实现viewForAnnotation 方法,地图视图将创建一个默认的注释视图,它是一个带有仅包含标题和副标题的标注的红色图钉(除非标题为空白,在这种情况下您将获得一个图钉但没有标注)。

    要么将地图视图的delegate 出口连接到文件的所有者,要么在代码中添加这个(例如,在添加注释之前的viewDidLoad):

    mapView.delegate = self;
    

    此外,如果您不使用 ARC,请将 autorelease 添加到 alloc 行以避免内存泄漏。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多