Issue
I have some map view controller and I have a custom annotation.
Custom annotation code:
#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>
@interface DisplayMapAnnotation : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
NSString *detailID;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
@property (nonatomic, retain) NSString *detailID;
@end
#import "DisplayMapAnnotation.h"
@implementation DisplayMapAnnotation
@synthesize coordinate, title, subtitle, detailID;
- (NSString *) title
{
return title;
}
- (NSString *) subtitle
{
return subtitle;
}
- (NSString *) detailID
{
return detailID;
}
- (id)initWithCoordinate:(CLLocationCoordinate2D) c
{
coordinate=c;
return self;
}
- (void) dealloc
{
[title release];
[subtitle release];
[detailID release];
[super dealloc];
}
A here is my map view code where I create the annotation: In viewDidLoad method I make something like this:
for (FeedItems *aItem in geoDataList) {
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [aItem.geoLat doubleValue];
region.center.longitude = [aItem.geoLng doubleValue];
region.span.longitudeDelta = kLatitudeDelta;
region.span.latitudeDelta = kLongitudeDelta;
[mapView setRegion:region animated:YES];
ann = [[DisplayMapAnnotation alloc] init];
ann.title = aItem.job;
ann.subtitle = aItem.jobCompany;
ann.detailID = aItem.jobID;
ann.coordinate = region.center;
[mapView addAnnotation:ann];
[aItem release];
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
MKPinAnnotationView *pinView = nil;
if (annotation != self.mapView.userLocation) {
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil)
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
if (mapIdentifier == 0) {
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
//NSInteger annotationValue = [annView indexOfObject:annotation];
//rightButton.tag = annotationValue;
[rightButton addTarget:self action:@selector(detailButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
}
} else {
[self.mapView.userLocation setTitle:@"your location"];
}
return pinView;
}
And here is my problem (this method):
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"Detail id: %@", view.annotation.detailID);
}
When I will log detail id Xcode say: "Property 'detailID' not found on object of type 'id'" What is wrong ?
Solution
It does not know that the annotation is your custom annotation:
NSLog(@"Detail id: %@", view.annotation.detailID);
You could cast it like this to silence the warning
NSLog(@"Detail id: %@", [(DisplayMapAnnotation*)view.annotation detailID]);
after having checked that it is a DisplayMapAnnotation*
if ([view.annotation isKindOfClass:[DisplayMapAnnotation class]])
Answered By - jbat100
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.