PDA

View Full Version : Multiple Pins With Dynamic Titles




macprogrammer80
Aug 14, 2009, 06:27 AM
OK, I'm sure I'm missing something fundamental here, but here's what I want to do - I have about 10 pins all on the screen at once. As you would expect, when you tap on a pin to get the callout/bubble, I want each pin to have different text within it. I'm using the following code:

To draw the pin:



AddressAnnotation *showRedFlag;

redFlag.latitude = -33.840786;
redFlag.longitude = 151.205338;
showRedFlag = [[AddressAnnotation alloc] initWithCoordinate:redFlag];

[mapView addAnnotation:showRedFlag];



And the .h file for AddressAnnotation:


#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKAnnotation.h>

@interface AddressAnnotation : NSObject<MKAnnotation>
{
CLLocationCoordinate2Dcoordinate;
NSString *returnResult;
NSString *mTitle;
NSString *mSubTitle;
}

@end



And the .m file for AddressAnnotation:


@implementation AddressAnnotation

@synthesize coordinate;

- (NSString *)subtitle
{
return @"subtitle";
}

- (NSString *)title
{
return @"title";
}

-(id)initWithCoordinate:(CLLocationCoordinate2D) c
{
coordinate=c;
returnself;
}

@end



All I wanted to do was every time I draw my different flags the way that I do for the red flag in the top piece of code, I wanted to change the title, but no matter what I try, AddressAnnotation will not have dynamic titles. Can I just call something along the lines of :


redFag.title = @"unique title";
redFlag.subtitle = @"unique subtitle"


Thanks in advance!