Brandon
Brandon

Reputation: 2171

Set ViewController Title from calloutAccessoryControlTapped

I am trying to simply set the title of a detailViewController to the title of a pin once the call out accessory control is tapped.

Here is where I set the MKAnnotation up:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id 
<MKAnnotation>)annotation
{
MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] 
initWithAnnotation:annotation reuseIdentifier:@"loc"];

Here is where I want to set the title of the detail view controller to the pin title:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view     
calloutAccessoryControlTapped:(UIControl *)control
{

DetailViewController *controller = [[DetailViewController alloc] initWithNibName:nil
                                                                            bundle:nil];
[self.navigationController pushViewController:controller animated:YES]; // or use     
presentViewController if you're using modals

controller.title = pin.annotationView.subtitle;

}

The last line is what is messed up. Any ideas? Thank you all!!

Upvotes: 0

Views: 408

Answers (2)

Vinodh
Vinodh

Reputation: 5268

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view     
calloutAccessoryControlTapped:(UIControl *)control
{
MKAnnotation * annotation = (MKAnnotation *)annotation;

DetailViewController *controller = [[DetailViewController alloc] initWithNibName:nil
                                                                            bundle:nil];
controller.title = annotation.subtitle;

[self.navigationController pushViewController:controller animated:YES]; // or use     
presentViewController if you're using modals

}

The above code works fine for me Mr.Brandon

Upvotes: 1

Brandon
Brandon

Reputation: 2171

Figured it out - replaced the controller title with:

controller.title = view.annotation.title;

Thanks all!

Upvotes: 2

Related Questions