So in one view, I have a button the pushes another viewController with a map. The map let's the user select any location and provides an annotation with the reverseGeocode address of that location. The annotation has a button that 'pops' the view controller. Now when that button is pressed, I want it to update a label on the original view. How can this be done?
View 1 with button and label:
Code:
- (IBAction) pickLocation {
MapViewController *mapcontroller = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
mapcontroller.navigationItem.title = @"Pick Location";
[self.navigationController pushViewController:mapcontroller animated:YES];
[mapcontroller release];
}
View 2 with Map and annotation:
Code:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
if ([control isKindOfClass:[UIButton class]]) {
View1Controller *view1 = [[ View1Controller alloc] init];
view1._address = address; // 'address' is synthesized in view2
[view1 release];
[self.navigationController popViewControllerAnimated:YES];
}
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)newPlacemark {
for (DDAnnotation *annotation in _annotations) {
if (annotation.coordinate.latitude == geocoder.coordinate.latitude && annotation.coordinate.longitude == geocoder.coordinate.longitude) {
annotation.subtitle = [[newPlacemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
address = [NSString stringWithFormat:@"%@", annotation.subtitle]; // 'address' is synthesized properly
}
}
}
The issue is the label ends up being null. How do I ensure the 'address' value from view2 gets stored as a string in view1 then displayed in the label in view1?
Banging my head on this one...