Reputation: 33644
So I have a map view in which if I tap on the accessory view it would push a new view to the navigation controller. The issue is that I would also like to set a local variable of that view controller when this is tapped (in my view controller I have an instance called venue in which I'd like to set) The delegate that I am implementing is:
- (void) mapView: (MKMapView *) mapView annotationView:(MKAnnotationView *) view calloutAccessoryControlTapped:(UIControl *) control
What I was thinking was to subclass the MKAnnotationView and then have a venue stored there as well, but I think this defeats the purpose as MKAnnotationView is only supposed to be a view instead of a data storage. So what is the best way to do this?
In other words, the problem is that, each pin has a venue that I need to pass to the view controller instance through the delegate above.
Upvotes: 1
Views: 52
Reputation:
If your annotation object (a class which conforms to MKAnnotation
) already has a venue property, you can access it in calloutAccessoryControlTapped
using view.annotation
like this:
MyAnnotationClass *myAnnot = (MyAnnotationClass *)view.annotation;
DetailViewController *dvc = [[DetailViewController alloc] init...
dvc.venue = myAnnot.venue;
[self.navigationController pushViewController:dvc animated:YES];
[dvc release];
Upvotes: 1