我試圖在地圖註記視圖上將細節披露指示符連接到segue。出於某種原因,它正在崩潰。僅供參考 - 我已經從UIButton
(在故事板中創建控制拖動連接)開始工作。嘗試在地圖註記視圖上將細節披露指示符連接到segue方法
我用下面的代碼得到的錯誤是「無法識別的選擇器發送到實例」。
這裏是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]];
}
}
感謝您的幫助。我試過,但得到一個「無法識別的選擇器發送到實例」錯誤... – hanumanDev 2012-04-27 21:56:35
任何想法如何我會從另一種方法調用此方法: - (void)prepareForSegue :(UIStoryboardSegue *)segue sender:(id)sender {} – hanumanDev 2012-04-27 21:58:52