开发者

MKAnnotation - adding url

开发者 https://www.devze.com 2023-02-24 07:21 出处:网络
I\'m working through mayurbirari\'s sample code to generate a mapkit view, I want to add a url to the popup.I\'ve tried to understand the apple reference to subclass but TBH it just isnt going it.

I'm working through mayurbirari's sample code to generate a mapkit view, I want to add a url to the popup. I've tried to understand the apple reference to subclass but TBH it just isnt going it.

I need to create a subclass that can have additional variable added to it as MKANNOTATION is core file and cannot be changed - therefore how do I do it?? I'm confused about how to set it up.

the code can be found here --> http://mayurbirari.wordpress.com/2011/02/07/how-to-access-mkmapkit-in-iphone/

if someone could show me the开发者_JAVA技巧 example of the subclass with URL added to it, it would probably sink in, but all the examples I've found seem to be over complicated.


MKAnnotation is a protocol that you have to adopt in your own class -- whichever class you're using to represent an annotation object. This is often a class that's part of your data model. For example, you might have a Person class and want to show instances of Person on a map. You'd adopt MKAnnotation in Person. It's easy to use properties for this:

@interface Person : NSObject <MKAnnotation>
{
   //...
}
//...
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
@end

And then implement the methods from MKAnnotation in your class:

@implementation Person

@synthesize coordinate;
@synthesize title;
@synthesize subtitle;

//...various methods of Person...

@end

Now you can add instances of Person to the map as annotations.

0

精彩评论

暂无评论...
验证码 换一张
取 消