Accessing Custom Annotation Enumerator Type Not Working
Hey, I am having problems accessing a variable within a custom annotation class I defined. Here is the relevant code:
ArboretumAnnotation.h(custom annotation class header):
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
typedef enum { //correspond to permit types
arboAnnoTypeNone = 0,
arboAnnoTypeShieldsOakGrove
} arboAnnoType;
@interface ArboretumAnnotation : NSObject <MKAnnotation> {
NSString *title;
NSString *subtitle;
UIImage *image;
CLLocationCoordinate2D coordinate;
arboAnnoType annotEnumType;
}
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
@property (nonatomic, retain) UIImage *image;
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic) arboAnnoType annotEnumType;
@end
Please note that all declared properties have been synthesized in the implementation file.
MapViewController.m:
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
//show detail view but first set the view with the appropriate title
LocationDetailViewController *locationDetail = [[LocationDetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
NSLog(@"permitDetail.title: %@", locationDetail.title);
if (view.annotation.annotEnumType == arboAnnoTypeShieldsOakGrove) { //PROBLEM LINE
locationDetail.title = @"Shields Oak Grove";
locationDetail.annotEnumType = arboAnnoTypeShieldsOakGrove;
}
else {
locationDetail.title = view.annotation.title;
locationDetail.annotEnumType = arboAnnoTypeNone;
}
[self.naviga开发者_C百科tionController pushViewController:locationDetail animated:YES];
[locationDetail release];
}
At the line with the comment: //PROBLEM LINE
I am getting the following error:
MapViewController.m:148: error: accessing unknown 'annotEnumType' getter method
Even if I change that line to:
if ([view.annotation annotEnumType] == arboAnnoTypeShieldsOakGrove) {
I get the following warning:
MapViewController.m:148: warning: '-annotEnumType' not found in protocol(s)
Any idea what I am doing wrong? Thanks in advance!
Try to first cast it to your custom annotation type because the annotation property by itself is just id<MKAnnotation>
:
ArboretumAnnotation *arboretumAnnot = (ArboretumAnnotation *)view.annotation;
if (arboretumAnnot.annotEnumType == arboAnnoTypeShieldsOakGrove) {
精彩评论