views:

44

answers:

1

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, 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.

+4  A: 

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.

Jeff Kelley
Sorry, can you clarify what you mean by "Property Variable"? I do have an instance variable of itemID defined as NSString *itemID ... do I need to do something else special with this? The code is actually working (reverted to original mapkit.framework), but it is giving me that same warning.
Chris
Check the edit.
Jeff Kelley
I already have that in myAnnotation.h/m. To be clear, I have myAnnotation.h/m and MapViewController.h/m. I am trying to use currentAnnotation.itemID within MapViewController.h/m. Based on your example and what I already see in the code, I am assuming I should be defining itemID inside myAnnotation.h/m - but I am still receiving the same "not found in protocol" warning.
Chris
The warning is actually appearing when I am retrieving the value from currentAnnotation.itemID, in a later Method. There is no warning when I am putting the value into currentAnnotation.itemID.
Chris
if I do [currentAnnotation itemID], it gives me a warning. If I do currentAnnotation.itemID, it gives me an error. Only when I am pulling data out, not when putting it in.
Chris
I edited again - hopefully this solves the problem.
Jeff Kelley
Thanks so much - the problem was that I was referencing itemID inside of the viewForAnnotation method, which uses (<MKAnnoation>)annotation. I changed it to (myAnnotation)annotation and it cleared up the bugs.
Chris