
这是我的ArtPIEce.h:
#import <Foundation/Foundation.h>#import <MapKit/MapKit.h>@interface ArtPIEce : NSObject <MKAnnotation>{ Nsstring *Title; Nsstring *artist; Nsstring *serIEs; Nsstring *description; Nsstring *location; Nsstring *area; NSNumber *latitude; NSNumber *longitude; UIImage *image;}@property (nonatomic,retain) Nsstring *Title;@property (nonatomic,retain) Nsstring *artist;@property (nonatomic,retain) Nsstring *serIEs;@property (nonatomic,retain) Nsstring *description;@property (nonatomic,retain) Nsstring *location;@property (nonatomic,retain) Nsstring *area;@property (nonatomic,retain) NSNumber *latitude;@property (nonatomic,retain) NSNumber *longitude;@property (nonatomic,retain) UIImage *image;@end 这里是.m:
#import "ArtPIEce.h"#import "FindArtController.h"#import "ArtPIEce.h"#import <MapKit/MapKit.h>@implementation ArtPIEce- (Nsstring *)description{ return [Nsstring stringWithFormat:@"Title: %@",Title];}@synthesize Title,artist,serIEs,description,latitude,longitude,location,area,image;- (CLLocationCoordinate2D)coordinate{ CLLocationCoordinate2D theCoordinate; theCoordinate.latitude = [self.latitude doubleValue]; theCoordinate.longitude = [self.longitude doubleValue]; return theCoordinate;}@end 然后,我继续创建该类的对象,设置它们的值,并将它们添加到AppDelegate中的数组中.然后,在另一个班上,我使用:
[self.mapVIEw addAnnotations:mainDelegate.mapAnnotations];
将注释添加到地图.但是,当我尝试在vIEwofannotation方法中设置“艺术家”属性时,我得到“要求成员不是结构或联盟的东西”.
显然,我一定是做这个子类的事情错了,但是我该怎么改?
这里是我现在的意见方法. test.artist …行不行.
- (MKAnnotationVIEw *)mapVIEw:(MKMapVIEw *)mapVIEw vIEwForAnnotation:(ID <MKAnnotation>)annotation{ MKAnnotationVIEw *test=[[MKAnnotationVIEw alloc] initWithAnnotation:annotation reuseIDentifIEr:@"reuse"]; test.image = [UIImage imagenamed:@"pao_pin.png"]; [test setCanShowCallout:YES]; [test setUserInteractionEnabled:YES]; test.rightCalloutAccessoryVIEw = [UIbutton buttonWithType:UIbuttonTypeDetaildisclosure]; test.artist = annotation.artist; return test; } 所以,我应该:注释=(ArtPIEce *)注释
简而言之,我的目标是能够存储对这个注释中对象的数组位置的引用,这样我就可以发送给可以访问该对象的其他方法来获取详细视图.
你需要这样的东西:
ArtPIEce *artPIEce = (ArtPIEce *)annotation;Nsstring *artist = artPIEce.artist;
编辑:
当按下注释视图的标注按钮时,地图视图将调用calloutAccessoryControlTapped委托方法.该方法通过视图参数中的MKAnnotationVIEw.注释对象本身在vIEw参数的注释属性中.您可以将该对象转换为您的自定义类来访问您的ArtPIEce属性:
- (voID)mapVIEw:(MKMapVIEw *)mapVIEw annotationVIEw:(MKAnnotationVIEw *)vIEw calloutAccessoryControlTapped:(UIControl *)control{ ArtPIEce *artPIEce = (ArtPIEce *)vIEw.annotation; Nsstring *artist = artPIEce.artist;} 换句话说,标注按钮处理程序不需要访问原始数组.它引用了实际的ArtPIEce对象本身.
总结以上是内存溢出为你收集整理的objective-c – 将数据存储在MKAnnotation中?全部内容,希望文章能够帮你解决objective-c – 将数据存储在MKAnnotation中?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)