Reputation: 569
I get geolocations for annotations on map and would like to show user related image from the same row in a custom view.
I've tried saving PFFiles in a dictionary along with ObjectIDs because I'm setting each annotation's title its location's ObjectID but that gives me - [PFObject objectID]: unrecognized selector sent to instance.
This is what I'm currently doing.
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");
}
}];
And then
- (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;}
Edit
I've realized I had to do this in order to make it work with PFFiles
PFFile *imageFile = object[@"photo"];
[imageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
self.callOutImage = [UIImage imageWithData:imageData];
}}];
But still not working.
Upvotes: 1
Views: 94
Reputation: 569
Solved it..
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];
}}];
I had to set the images inside getDataInBackgroundWithBlock since I'm getting PFFiles for UIImages in background otherwise images get no data.
Upvotes: 1