我正在尝试将 map 注释 View 上的详细信息披露指示器连接到 segue。由于某种原因,它正在崩溃。仅供引用 - 我已经通过 UIButton
(在 Storyboard 中创建了控件拖动连接)进行了此操作。
我在使用以下代码时遇到的错误是“无法识别的选择器已发送到实例”。
这是带有详细披露指示符的 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]];
}
}
最佳答案
您没有显式调用 prepareForSegue 方法,您应该做的是创建另一个方法来执行 segue 的更改。像这样:
你必须改变你的 mapView:map viewForAnnotation:annotation 方法改变这一行
[disclosureButton addTarget:self action:@selector(myMethod) forControlEvents:UIControlEventTouchUpInside];
然后在您的方法中执行 View 的更改
-(void)myMethod{
[self performSegueWithIdentifier:@"ShowMoreInfo" sender:self];
}
我认为这应该可行。
关于objective-c - 尝试将 map 注释 View 上的详细信息披露指示器连接到 segue 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10352892/