iPhone: addAnnotation not working when called from another view

Posted by Nic Hubbard on Stack Overflow See other posts from Stack Overflow or by Nic Hubbard
Published on 2010-05-25T05:20:54Z Indexed on 2010/05/25 7:11 UTC
Read the original article Hit count: 404

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?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk