我有一个地图注释,我想在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