我正在尝试将地图注释视图上的详细信息披露指示器连接到 segue。由于某种原因,它正在崩溃。仅供参考 - 我已经通过UIButton
(在情节提要中建立了控制拖动连接)进行了这项工作。
我使用以下代码得到的错误是“无法识别的选择器发送到实例”。
这是MKAnnotationView
带有详细披露指标的代码:
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *mapPin = nil;
if(annotation != map.userLocation)
{
static NSString *defaultPinID = @"defaultPin";
mapPin = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (mapPin == nil )
{
mapPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:defaultPinID];
mapPin.canShowCallout = YES;
UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[disclosureButton addTarget:self action:@selector(prepareForSegue:) forControlEvents:UIControlEventTouchUpInside];
mapPin.rightCalloutAccessoryView = disclosureButton;
}
else
mapPin.annotation = annotation;
}
return mapPin;
}
这是prepareForSegue
方法:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure we're referring to the correct segue
if ([[segue identifier] isEqualToString:@"ShowMoreInfo"]) {
// Get reference to the destination view controller
MoreDetailViewController *mdvc = [segue destinationViewController];
[mdvc setSelectedItemName:[NSString stringWithFormat:@"%@", placeName.text]];
[mdvc setSelectedItemAddress:[NSString stringWithFormat:@"%@", placeFormattedAddress.text]];
[mdvc setSelectedItemWeb:[NSString stringWithFormat:@"%@", placeWebsite.text]];
[mdvc setSelectedItemRating:[NSString stringWithFormat:@"%@", placeRating.text]];
// [mdvc setSelectedItemDistance:[NSString stringWithFormat:@"%@", placeDistance.text]];
}
}