你为什么要修改框架?您应该在myAnnotation.h
中将itemID
定义为属性或实例变量(或两者)。你说currentAnnotation.itemTag
没有工作;为了工作,您需要将itemTag
定义为currentAnnotation
所属类别的属性。
更改框架的头文件不会重新编译它,所以您将无法使其工作。
编辑:下面是一个例子。
在:
@interface MyAnnotation : NSObject <MKAnnotation> {
NSString *itemID;
// Other instance variables
}
@property (nonatomic, retain) NSString *itemID;
// Class and instance methods.
@end
在MyAnnotation.m
:
@implementation MyAnnotation
@synthesize itemID;
// Your code here.
@end
的@property
调用定义属性和@synthesize
通话将创建getter和setter方法为你(的方法来设置和获取价值itemID
)。在MyAnnotation.m
中,可以使用self.itemID
或[self itemID]
来获得itemID
的值,并且可以使用self.itemID = @"something"
或[self setItemID:@"Something"]
来设置该值。
编辑2:
当你得到currentAnnotation
,如果编译器不知道的注释是您MyAnnotation类的实例,也不会知道itemID
。所以,首先确保你已经包括这条线在你.m
文件的开头:
#import MyAnnotation.h
那西港岛线确保编译器知道的类。当您使用currentAnnotation
,你施放它作为MyAnnotation
一个实例,像这样:
(MyAnnotation*)currentAnnotation
这应该安静下来的警告。
对不起,你能解释一下“Property Variable”的含义吗?我确实有一个itemID的实例变量被定义为NSString * itemID ...我是否需要对此做其他特别的事情?代码实际上正在工作(回复到原始的mapkit.framework),但它给了我相同的警告。 – Chris 2010-03-23 17:43:32
检查编辑。 – 2010-03-23 18:13:13
我已经在myAnnotation.h/m中有。要清楚,我有myAnnotation.h/m和MapViewController.h/m。我想在MapViewController.h/m中使用currentAnnotation.itemID。 根据您的示例以及我已经在代码中看到的内容,我假设我应该在myAnnotation.h/m中定义itemID - 但我仍然收到“在协议中找不到”警告。 – Chris 2010-03-23 18:53:29