2012-04-27 53 views
1

我試圖在地圖註記視圖上將細節披露指示符連接到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]]; 

     } 
    } 

回答

1

你不顯式調用prepareForSegue方法,你應該做的是創造另一個執行賽格變化的方法。事情是這樣的:

你必須改變你的MapView:地圖viewForAnnotation:標註方法改變這一行

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

然後在你的方法,你執行視圖

-(void)myMethod{ 
[self performSegueWithIdentifier:@"ShowMoreInfo" sender:self]; 
} 

我覺得變化這應該工作。

+0

感謝您的幫助。我試過,但得到一個「無法識別的選擇器發送到實例」錯誤... – hanumanDev 2012-04-27 21:56:35

+0

任何想法如何我會從另一種方法調用此方法: - (void)prepareForSegue :(UIStoryboardSegue *)segue sender:(id)sender {} – hanumanDev 2012-04-27 21:58:52