MKAnnotation - 添加 url

发布于 2024-11-01 00:02:12 字数 436 浏览 2 评论 0原文

我正在通过 mayurbirari 的示例代码生成一个 Mapkit 视图,我想向弹出窗口添加一个 url。我试图理解苹果对子类的引用,但说实话,它只是没有实现。

我需要创建一个子类,可以添加额外的变量,因为 MKANNOTATION 是核心文件并且无法更改 - 那么我该怎么做?我对如何设置它感到困惑。

代码可以在这里找到 --> http://mayurbirari.wordpress.com/ 2011/02/07/how-to-access-mkmapkit-in-iphone/

如果有人可以向我展示添加了 URL 的子类示例,它可能会被吸收,但我的所有示例我发现似乎过于复杂。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷鸟归林 2024-11-08 00:02:12

MKAnnotation 是您必须在自己的类中采用的协议——无论您使用哪个类来表示注释对象。这通常是属于数据模型一部分的类。例如,您可能有一个 Person 类并希望在地图上显示 Person 的实例。您将亲自采用 MKAnnotation。为此,使用属性很容易:

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

然后在您的类中实现 MKAnnotation 的方法:

@implementation Person

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

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

@end

现在您可以将 Person 的实例作为注释添加到地图中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文