我正在尝试将地图注释视图上的详细信息披露指示器连接到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]];
}
}
答案 0 :(得分:1)
您没有明确调用prepareForSegue方法,您应该做的是创建另一个执行segue更改的方法。像这样:
您必须更改mapView:map viewForAnnotation:注释方法更改此行
[disclosureButton addTarget:self action:@selector(myMethod) forControlEvents:UIControlEventTouchUpInside];
然后在您的方法中执行视图的更改
-(void)myMethod{
[self performSegueWithIdentifier:@"ShowMoreInfo" sender:self];
}
我认为这应该有用。
答案 1 :(得分:1)
我怀疑在显示注释并选择标注后,使用mapView:didSelectAnnotationView:然后mapView:annotationView:calloutAccessoryControlTapped:可以帮助您。