1

我有一个带有详细信息披露指示器的 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]];

    }
}
4

2 回答 2

0

prepareForSegue: 和 prepareForSegue:sender: 不是同一种方法。您的 prepareForSegue:sender: 方法中的 placeName 和朋友也是未知的(或者是 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];

如果你喜欢注释和地图,你不应该使用更适合简单导航的 segues。

于 2012-04-30T16:26:51.417 回答
0

您在那里有两种详细视图控制器,一种MoreDetailViewController在您的代码中,一种DetailViewController在您的错误中。你有可能把它们混在一起吗?

于 2012-04-30T12:52:40.967 回答