2012-04-27 4 views
1

マップアノテーションビューの詳細開示インジケータをセグエフに接続しようとしています。何らかの理由でクラッシュしています。 FYI - 私はこれをUIButton(ストーリーボードでコントロールのドラッグ接続を使用して)から作業しました。マップアノテーションビュー上の詳細開示インジケータをセグエメソッドにフックしよう

次のコードでは「インスタンスに送信されたセレクタが認識されません」というエラーが表示されます。

ここでは詳細な開示インジケータ付きMKAnnotationViewコードです:

- (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メソッドを呼び出すことはありません:

- (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方法だが、 segueの変更を実行するメソッドです。このような何か:あなたのMapViewを変更する必要が

:マップviewForAnnotation:注釈方法は、その後、あなたの方法であなたが

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

は、私が思うのビューの変更を行うこのライン

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

を変更しますそれはうまくいくはずです。

+0

ありがとうございました。私はそれを試みたが、インスタンスに送信された "認識されないセレクタ"エラーを取得する... – hanumanDev

+0

私は別のメソッドからこのメソッドをどのように呼び出すか考えてみましょう:(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { – hanumanDev

関連する問題