2

我有一个带有注释的MKMapView ,允许用户选择他们想要的位置。为此,他们触摸大头针,这会在标注中显示名称和地址,他们可以触摸以选择该位置。leftCalloutAccessoryView

如果他们触摸我要删除的Edit按钮并添加一个. 现在,我不想选择位置,而是为用户打开一个编辑器来修改信息。navigationItemleftCalloutAccessoryViewrightCalloutAccessoryView

执行此操作的代码是:

- (void) setEditing: (BOOL) editing animated: (BOOL) animate {
    NSLog( @"Entering %s", __func__ );
    [super setEditing: editing animated: animate];
    // Hide/show the back button consistent with the editing phase...
    // (i.e., hidden while editings, shown when not editing)
    [self.navigationItem setHidesBackButton: editing animated: animate];

    // Modify the mapview annotations
    for( id a in self.mapView.annotations ) {
        MKAnnotationView *av = [self.mapView viewForAnnotation: a];
        av.leftCalloutAccessoryView = editing ? nil : [self chooseLocationAccessoryButton];
        av.rightCalloutAccessoryView = editing ? [UIButton buttonWithType: UIButtonTypeDetailDisclosure] : nil;
    }
}

- (void) mapView: (MKMapView *) mapView annotationView: (MKAnnotationView *) view calloutAccessoryControlTapped: (UIControl *) control {
    NSLog( @"Entering %s", __func__ );
    if( control == view.leftCalloutAccessoryView ) {
        NSLog( @"-- Left button pressed" );
    } else if( control == view.rightCalloutAccessoryView ) {
        NSLog( @"-- Right button pressed" );
    } else {
        NSLog( @"-- Neither right not left button pressed?" );
    }

    if( self.editing ) {
        NSLog( @"-- Should be pushing to edit this location..." );
    } else {
        [self.delegate locationPicker: self didSelectLocation: selectedLocation];
    }
}

除非在我更改编辑模式时标注可见,否则mapView:annotationView:calloutAccessoryControlTapped:方法会被正确调用。附件视图很好地使自己进出动画,但除非我触摸其他地方,否则它们不起作用,因此标注消失,然后再次触摸大头针以显示它。

如果我更改编辑模式,然后触摸一个大头针,标注会显示正确的附件视图并且它可以正常工作。

我觉得我必须遗漏一些东西。任何人都可以帮助保持我的按钮正常工作吗?

4

0 回答 0