Editing and iPhone SDK Framework?
I am working with MapKit and want to be able to add a (NSString *)itemTag value to each of my annotations. I have created myAnnotiation.m and myAnnotation.h
I tried adding itemTag to the myAnnotation.h/m but when I try to access currentAnnotation.itemTag within my main code开发者_Go百科, it says "itemID not found in protocols" - so I went to the MapKit.Framework and into MKAnnotation.h. I added (NSString *)itemID, but when I save the .h file in the Framework, it changes the file's icon and doesn't appear to by jiving with everything else.
Any help or links to help would be greatly appreciated. I am not even sure if I'm on the right path here, but Googling "modify iphone sdk framework" does not turn up much.
Why are you trying to modify the framework? You should be defining itemID
as a property or instance variable (or both) in myAnnotation.h
. You say that currentAnnotation.itemTag
didn't work; for that to work, you need to have itemTag
defined as a property of whatever class currentAnnotation
belongs to.
Changing the header file for the framework won't recompile it, so you won't be able to get that to work.
EDIT: Here's an example.
In MyAnnotation.h
:
@interface MyAnnotation : NSObject <MKAnnotation> {
NSString *itemID;
// Other instance variables
}
@property (nonatomic, retain) NSString *itemID;
// Class and instance methods.
@end
In MyAnnotation.m
:
@implementation MyAnnotation
@synthesize itemID;
// Your code here.
@end
The @property
call defines the property and the @synthesize
call will create setters and getters for you (methods to set and retrieve the value of itemID
). In MyAnnotation.m
, you can use self.itemID
or [self itemID]
to get the value of itemID
, and you can use self.itemID = @"something"
or [self setItemID:@"Something"]
to set the value.
EDIT 2:
When you get currentAnnotation
, if the compiler doesn't know that the annotation is an instance of your MyAnnotation class, it won't know about itemID
. So, first ensure that you've included this line at the beginning of your .m
file:
#import MyAnnotation.h
That wil ensure that the compiler knows about the class. When you use currentAnnotation
, you cast it as an instance of MyAnnotation
like so:
(MyAnnotation*)currentAnnotation
That should quiet down the warnings.
精彩评论