我有 MKMapView 和注释,以允许用户选择所需的位置。要执行此操作,他们会触摸图钉,这会在标注中显示名称和地址,并使用leftCalloutAccessoryView
可以触摸以选择该位置。
如果他们触及Edit
上的navigationItem
按钮,我想删除leftCalloutAccessoryView
并添加rightCalloutAccessoryView
。现在,而不是选择我想打开编辑器的位置,以便用户修改信息。
执行此操作的代码是:
- (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:
方法,除非在我更改编辑模式时标注可见。附件可以很好地进出自己的动画,但除非我触摸其他地方以使标注消失,然后再次触摸该针以显示它,否则它们不起作用。
如果我更改了编辑模式,然后触摸一个引脚,则会显示带有正确附件视图的标注,并且该标注功能正常。
我觉得我必须要留下一些东西。任何人都可以帮我保持我的按钮功能吗?