Objective c 尝试将地图注释视图上的详细信息披露指示器连接到segue方法
我正在尝试将地图注释视图上的细节披露指示器连接到一个序列。由于某种原因,它正在崩溃。仅供参考-我已经通过Objective c 尝试将地图注释视图上的详细信息披露指示器连接到segue方法,objective-c,ios,mapkit,segue,Objective C,Ios,Mapkit,Segue,我正在尝试将地图注释视图上的细节披露指示器连接到一个序列。由于某种原因,它正在崩溃。仅供参考-我已经通过ui按钮(在情节提要中创建了一个控件拖动连接)实现了这一点 下面代码中出现的错误是“无法识别的选择器发送到实例” 以下是带有详细信息披露指示器的MKAnnotationView代码: - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
ui按钮
(在情节提要中创建了一个控件拖动连接)实现了这一点
下面代码中出现的错误是“无法识别的选择器发送到实例”
以下是带有详细信息披露指示器的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方法,您应该创建另一个方法来执行segue的更改。大概是这样的: 您必须更改地图视图:地图视图注释:注释方法更改此行
[disclosureButton addTarget:self action:@selector(myMethod) forControlEvents:UIControlEventTouchUpInside];
然后在方法中执行视图的更改
-(void)myMethod{
[self performSegueWithIdentifier:@"ShowMoreInfo" sender:self];
}
我认为这应该行得通。我想在显示注释并选择标注之后,使用和会对您有所帮助。谢谢您的帮助。我试过了,但是得到了一个“无法识别的选择器发送到实例”错误…你知道我如何从另一个方法调用这个方法吗:-(void)prepareforsgue:(UIStoryboardSegue*)segue sender:(id)sender{}谢谢你的回答。我不知道我该如何用它来解决这个问题,尽管。。。
-(void)myMethod{
[self performSegueWithIdentifier:@"ShowMoreInfo" sender:self];
}