1

calloutAccessoryControlTappedに触れたときに詳細ビューコントローラーにプッシュしたい地図注釈があります。私が抱えている問題は、すべての注釈がすべて同じデータを詳細 VC に送信することです。indexPath が間違っているかどうかはわかりません。各地図の注釈は、吹き出しボックスに正しい情報を表示します。calloutAccessoryControlTappedタップすると、配列の最初のリストに同じ情報がプッシュされるようです。

それは NSNumber *catListingMapId; 私が本当にアクセスして詳細VCに渡す必要がある注釈で(そして、そのcatListingMapIdに基づいてデータをダウンロードします)。

- (void)mapView:(MKMapView *)mv annotationView:(MKAnnotationView *)pin calloutAccessoryControlTapped:(UIControl *)control {

    DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];

    MyAnnotation *theAnnotation = (MyAnnotation *) pin.annotation;

    NSLog(@"the Annotation %@",theAnnotation.catListingMapId);

    detailViewController.listingId = theAnnotation.catListingMapId;
  //  detailViewController.listingId = [[self.listingNodesArray objectAtIndex:selectedIndexPath] objectForKey:@"id"];

    NSNumber *catNumber = [NSNumber numberWithInt:[catID intValue]];

    detailViewController.catId = catNumber;

    NSLog(@"detailViewController.listingId  %@",detailViewController.listingId );
    [self.navigationController pushViewController:detailViewController animated:YES];
}

ここに私の myAntoationMap ファイルがあります:

@interface MyAnnotation : NSObject<MKAnnotation> {

CLLocationCoordinate2D  coordinate;
NSString*               title;
NSString*               subtitle;
NSNumber *latString;
NSNumber *lngString;

NSNumber *catMapId;
NSNumber *catListingMapId;

}

@property (nonatomic, assign)   CLLocationCoordinate2D  coordinate;
@property (nonatomic, copy)     NSString*               title;
@property (nonatomic, copy)     NSString*               subtitle;

@property (nonatomic,copy) NSNumber *latString;
@property (nonatomic,copy) NSNumber *lngString;
@property (nonatomic,copy) NSNumber *catMapId;
@property (nonatomic,copy) NSNumber *catListingMapId;

@end


and the .m

    #import "MyAnnotation.h"

@implementation MyAnnotation

@synthesize title;
@synthesize subtitle;
@synthesize coordinate;
@synthesize latString,lngString;
@synthesize catMapId;
@synthesize catListingMapId;

- (void)dealloc 
{
    [super dealloc];
    self.title = nil;
    self.subtitle = nil;
    self.latString = nil;
    self.lngString = nil;
    self.catMapId = nil;
    self.catListingMapId = nil;
}
@end
4

3 に答える 3

6

MKMapViewDelegate には次のデリゲート メソッドがあり、ユーザーが calloutAccessory ボタンをタップするたびに呼び出されるため、ここで注釈のタイトルとサブタイトルを取得します。これらの値を使用して、次の viewController にデータを渡すことができます。

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"%@",view.annotation.title);
    NSLog(@"%@",view.annotation.subtitle);
}
于 2013-09-10T09:36:51.177 に答える