我有一个带有详细信息披露指示的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]];
}
}
答案 0 :(得分:0)
您有两种详细视图控制器,代码中为MoreDetailViewController
,错误中为DetailViewController
。你有可能将它们混合起来吗?
答案 1 :(得分:0)
prepareForSegue:和prepareForSegue:sender:方法不一样。您的prepareForSegue:sender:方法中的placeName和friends也是未知的(或者是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。