objective-c - 尝试将 map 注释 View 上的详细信息披露指示器连接到 segue 方法

标签 objective-c ios mapkit segue

我正在尝试将 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/

相关文章:

ios - UIPrintInteractionController 不显示本地化文本

mapkit - 如何判断 CLLocationManager 是否正在监视重大位置更改

objective-c - Cocoa 应用程序的语法着色

objective-c - 在内存中保存长字符串的最佳方法是什么? ( cocoa )

objective-c - 在 iOS 上访问最近通话

ios - NSMutableArray 中的 BOOL 给出了错误的答案

ios - 以编程方式刷新 mapview 用户位置

ios - Swift MapKit - 注释不显示在 MapView 中

iphone - 在服务器和 iOS 应用程序之间同步文件目录

iphone - 在模态视图关闭时从选项卡栏项目中删除选择图像