我正在使用mayurbirari的示例代码来生成一个mapkit视图,我想在弹出窗口中添加一个url。我试着理解apple对subclass的引用,但它就是不能理解。
我需要创建一个子类,这个子类可以添加额外的变量,因为MKANNOTATION是核心文件,不能更改-因此我该怎么做?我对如何设置它感到困惑。
代码可以在这里找到--> http://mayurbirari.wordpress.com/2011/02/07/how-to-access-mkmapkit-in-iphone/
如果有人能向我展示添加了URL的子类的示例,它可能会被理解,但我发现的所有示例似乎都太复杂了。
发布于 2011-04-13 00:20:40
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实例作为注释添加到地图中。
https://stackoverflow.com/questions/5638159
复制相似问题