访问自定义注释枚举器类型不起作用

时间:2011-04-18 20:06:20

标签: cocoa-touch ios4 annotations mkmapview getter

嘿,我在访问我定义的自定义注释类中的变量时遇到问题。以下是相关代码:

ArboretumAnnotation.h(自定义注释类标题):

#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

请注意,所有声明的属性都已在实现文件中合成。

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.navigationController pushViewController:locationDetail animated:YES];
    [locationDetail release];

}

在评论的行中://PROBLEM LINE我收到以下错误:

MapViewController.m:148: error: accessing unknown 'annotEnumType' getter method

即使我将该行更改为:

if ([view.annotation annotEnumType] == arboAnnoTypeShieldsOakGrove) {

我收到以下警告:

MapViewController.m:148: warning: '-annotEnumType' not found in protocol(s)

知道我做错了什么吗?提前谢谢!

1 个答案:

答案 0 :(得分:1)

尝试首先将其强制转换为自定义注释类型,因为注释属性本身只是id<MKAnnotation>

ArboretumAnnotation *arboretumAnnot = (ArboretumAnnotation *)view.annotation;
if (arboretumAnnot.annotEnumType == arboAnnoTypeShieldsOakGrove) {