views:

194

answers:

1

I have two views, the first view has an MKMapView on it named ridesMap. The second view is just a view with a UITableView in it. When you click the save button in the second view, it calls a method from the first view:

// Get my first views class
MyRidesMapViewController *rideMapView = [[MyRidesMapViewController alloc] init];
// Call the method from my first views class that removes an annotation
[rideMapView addAnno:newRidePlacemark.coordinate withTitle:rideTitle.text withSubTitle:address];

This correctly calls the addAnno method, which looks like:

- (void)addAnno:(CLLocationCoordinate2D)anno withTitle:(NSString *)annoTitle withSubTitle:(NSString *)subTitle {

    Annotation *ano = [[[Annotation alloc] init] autorelease];

    ano.coordinate = anno;

    ano.title = annoTitle;

    ano.subtitle = subTitle;

    if ([ano conformsToProtocol:@protocol(MKAnnotation)]) {

        NSLog(@"YES IT DOES!!!");

    }

    [ridesMap addAnnotation:ano];

}//end addAnno

This method creates an annotation which does conform to MKAnnotation, and it suppose to add that annotation to the map using the addAnnotation method. But, the annotation never gets added.

I NEVER get any errors when the annotation does not get added. But it never appears when the method is called.

Why would this be? It seems that I have done everything correctly, and that I am passing a correct MKAnnotation to the addAnnotation method. So, I don't get why it never drops a pin? Could it be because I am calling this method from another view? Why would that matter?

+1  A: 

You are creating a second instance of MyRidesMapViewController. You should be adding the annotation to the original instance. You need to provide some means of passing that instance to your second view. There are many possible ways of doing this; the optimum choice depends on how your app is structured (which we don't know).

Paul Lynch
My app uses a tab bar controller. One of the tabs if my map view. On that tab, I have a button that shows a modal view, which opens over my mapview view. From this second view, is where I need to call my method, which would drop and annotation onto the mapview which is at the bottom of the stack.
Nic Hubbard
I suggest you scan the UITabViewController's viewControllers property to find your map view controller, and make it selected: self.tabBarController.selectedViewController = mapViewController;
Paul Lynch