触摸详细信息披露指示器时,地图视图注释崩溃



>我有一个带有细节披露指示器的 mapView,当触摸时需要将 MoreDetailViewController 带到堆栈上。目前,它崩溃并显示无法识别的选择器发送到实例错误。

我正在尝试弄清楚如何从披露指示器新闻中调用此方法- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

以下是带有披露指示器的地图注释代码:

- (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;
}

下面是应该调用的方法:

// Do some customisation of our new view when a table item has been selected
- (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: 和 prepareForSegue:sender: 不是相同的方法。还有地名和朋友在你的准备ForSegue:sender:方法未知(或者是ivars)。

我会从根本上改变 prepareForSegue:sender: 方法并将其更改为

- (void)showMoreInfo:(id)sender{
        // Get reference to the destination view controller
        MoreDetailViewController *mdvc = [segue destinationViewController];
//define and set the placename and other variables
        [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]];
    }
}

并以相同的方式调用它,只是更改调用的选择器的名称

[disclosureButton addTarget:self action:@selector(showMoreInfo:) forControlEvents:UIControlEventTouchUpInside];

如果您喜欢注释和地图,则不应使用更适合简单导航的 segue。

你有两种细节视图控制器,代码中的MoreDetailViewController和错误中的DetailViewController。你有没有可能把它们混在一起?

最新更新