访问自定义注释枚举器类型不起作用
嘿,我在访问我定义的自定义注释类中的变量时遇到问题。以下是相关代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试首先将其转换为您的自定义注释类型,因为注释属性本身只是
id
:Try to first cast it to your custom annotation type because the annotation property by itself is just
id<MKAnnotation>
: