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

发布于 2024-11-02 10:05:17 字数 2117 浏览 0 评论 0原文

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

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)

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

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.navigationController 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黎夕旧梦 2024-11-09 10:05:17

尝试首先将其转换为您的自定义注释类型,因为注释属性本身只是 id

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

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) {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文