I have an annotation view setup that adds a UIButton to rightCalloutAccessoryView. What I am trying to do is set the title of the button to the objectID of the parse object that the annotation represents.
My current result is that every annotation is getting the objectID of the first object in the query. What am I doing wrong here?
Looking at the code below what I am finding is that restaurantID is not being set each time a pin drops on the map. It seems to me I have it in the correct place as the title and subtitle of the pins update correctly.
Here is what I have done:
1.) In my mainViewController.h I have declared a string to hold the objectID of the PFobject:
@property (strong, nonatomic) NSString *restaurantID;
2.) In my mainViewController.m I have synthesized the variable
@synthesize restaurantID;
3.) In my PFquery I am setting this restaurantID to the objectID of the PFobject ( restaurantID = [object objectId];):
for (PFObject *object in objects) {
PFGeoPoint *point = [[object objectForKey:@"geoLocation"] init];
CLLocationCoordinate2D spot;
spot.latitude = point.latitude;
spot.longitude = point.longitude;
MKPointAnnotation *foodPoint = [[MKPointAnnotation alloc] init];
foodPoint.coordinate = (spot);
restaurantID = [object objectId];
foodPoint.title = [object objectForKey:@"restaurantName"];
foodPoint.subtitle = [object objectForKey:@"cuisineType"];
leftIcon = [object objectForKey:@"restaurantImage"];
[leftIcon getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
image = [UIImage imageWithData:data];
// image can now be set on a UIImageView
}
}];
[self.mainMap addAnnotation:foodPoint];
}
Then in my annotation view I set the title of the button to be the restaurantID:
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:restaurantID forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(buttonMethod:)
forControlEvents:UIControlEventTouchUpInside];
In my buttonMethod: I have an NSLog to display the title of the button pressed. The value remains the same as I click on different pins. It grabs the objectID of one Parse object, but it is not grabbing a new objectID for each object in the query.
Any ideas?