我在地图上获取注释的地理位置,并希望在自定义视图中显示来自同一行的用户相关图像。
我尝试将PFFiles与ObjectID一起保存在字典中,因为我将每个注释的标题设置为其位置的ObjectID,但这给了我 - [PFObject objectID] :无法识别的选择器发送到实例。
这就是我目前正在做的事情。
PFQuery *query = [PFQuery queryWithClassName:@"photoObject"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
for (id object in objects) {
[self.annotationArray addObject:object[@"location"]];
NSLog(@"Annotation's coordinate : %@", self.annotationArray);
UIImage *image = [UIImage imageWithData:object[@"photo"]];
[self.imageFileDict setObject:object[@"photo"] forKey:[object objectID]];
NSLog(@"imageFileDict : %@", self.imageFileDict);
self.geoPoint = object[@"location"];
CLLocationCoordinate2D locCoord = CLLocationCoordinate2DMake(self.geoPoint.latitude, self.geoPoint.longitude);
CustomPin *pin = [[CustomPin alloc] initWithTitle:[object objectId] location:locCoord image:image];
[self.mainMap addAnnotation:pin];
NSLog(@"Adding annotation");
}
}];
然后
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
CustomPin *pin = (CustomPin *)[view annotation];
NSLog(@"selected pin's objectID : %@",pin.title);
UIImageView *callOutview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width)];
[self.view addSubview:callOutview];
callOutview.backgroundColor = [UIColor yellowColor];
callOutview.image = pin.image;}
修改
我已经意识到我必须这样做才能使它与PFFiles一起使用
PFFile *imageFile = object[@"photo"];
[imageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
self.callOutImage = [UIImage imageWithData:imageData];
}}];
但仍然无法正常工作。
答案 0 :(得分:1)
解决了它..
PFFile *imageFile = object[@"photo"];
[imageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
[self.annotationArray addObject:object[@"location"]];
NSLog(@"Annotation's coordinate : %@", self.annotationArray);
self.callOutImage = [UIImage imageWithData:imageData];
self.geoPoint = object[@"location"];
CLLocationCoordinate2D locCoord = CLLocationCoordinate2DMake(self.geoPoint.latitude, self.geoPoint.longitude);
CustomPin *pin = [[CustomPin alloc] initWithTitle:[object objectId] location:locCoord image:self.callOutImage];
[self.mainMap addAnnotation:pin];
}}];
我必须在getDataInBackgroundWithBlock中设置图像,因为我在后台获取了UIImages的PFFiles,否则图像没有数据。