Question

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?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top