MapView add an action to custom annotation (the right arrow) - ios

I create the annotation pins via this for loop:
UIButton *eventMore = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
for (i = 0; i < [results count]; i++) {
//NSLog(#"Result: %i = %#", i, results[i]);
//NSLog(#"%#",[[results objectAtIndex:i] objectForKey:#"long"]);
myAnn = [[CustomAnnotation alloc] init];
location.latitude = (double)[[[results objectAtIndex:i] objectForKey:#"lat"] doubleValue];
location.longitude = (double)[[[results objectAtIndex:i] objectForKey:#"long"] doubleValue];
myAnn.coordinate = location;
myAnn.title = [[results objectAtIndex:i] objectForKey:#"title"];
myAnn.subtitle = [[results objectAtIndex:i] objectForKey:#"strap"];
[eventMore addTarget:myAnn action:#selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[locations addObject:myAnn];
//NSLog(#"%i", [[results objectAtIndex:i] objectForKey:#"lat"]);
}
What I am trying to do with this is add the detail disclosure button to the right of the title/description on the annotation however this does not add one in, and all the tuts I have found for this do it using this method - but it isnt working, any advice?
And the code for the action:
-(void)btnClicked:(id)sender{
UIAlertView *btnAlert = [[UIAlertView alloc] initWithTitle:#"title" message:#"msg" delegate:self cancelButtonTitle:#"cancel" otherButtonTitles:nil, nil];
[btnAlert show];
}

You are not setting the CalloutAccessoryView for your annotation.
Sample code
for (i = 0; i < [results count]; i++) {
MKPointAnnotation *myAnn = [[MKPointAnnotation alloc] init];
location.latitude = (double)[[[results objectAtIndex:i] objectForKey:#"lat"] doubleValue];
location.longitude = (double)[[[results objectAtIndex:i] objectForKey:#"long"] doubleValue];
myAnn.coordinate = location;
myAnn.title = [[results objectAtIndex:i] objectForKey:#"title"];
myAnn.subtitle = [[results objectAtIndex:i] objectForKey:#"strap"];
[locations addObject:myAnn];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
static NSString *s = #"ann";
MKAnnotationView *pin = [mapView dequeueReusableAnnotationViewWithIdentifier:s];
if (!pin) {
pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:s];
pin.canShowCallout = YES;
pin.image = [UIImage imageNamed:#"pin.png"];
pin.calloutOffset = CGPointMake(0, 0);
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[button addTarget:self
action:#selector(viewDetails) forControlEvents:UIControlEventTouchUpInside];
pin.rightCalloutAccessoryView = button;
}
return pin;
}

Related

Random MKPointAnnotation in map

In my project I fill my map with these informations
for (int i = 0; i<arrayResults.count; i++){
object = [arrayResults objectAtIndex:i];
if ([[object iden]intValue] == 1) {
type = #"type_one";
CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[object coord]objectForKey:#"latitude"] floatValue], [[[object coord]objectForKey:#"longitude"] floatValue]);
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [NSString stringWithFormat:#"%#",[object nome_obj]];
annotationPoint.subtitle = [NSString stringWithFormat:#"%#",[object address]];
[map addAnnotation:annotationPoint];
}
else if ([[object iden]intValue] == 2) {
type = #"type_two";
CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[object coord]objectForKey:#"latitude"] floatValue], [[[object coord]objectForKey:#"longitude"] floatValue]);
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [NSString stringWithFormat:#"%#",[object nome_obj]];
annotationPoint.subtitle = [NSString stringWithFormat:#"%#",[object address]];
[map addAnnotation:annotationPoint];
}
else if ([[object iden]intValue] == 3) {
type = #"type_three";
CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[object coord]objectForKey:#"latitude"] floatValue], [[[object coord]objectForKey:#"longitude"] floatValue]);
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [NSString stringWithFormat:#"%#",[object nome_obj]];
annotationPoint.subtitle = [NSString stringWithFormat:#"%#",[object address]];
[map addAnnotation:annotationPoint];
}
else if ([[object iden]intValue] == 4) {
type = #"type_four";
CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[object coord]objectForKey:#"latitude"] floatValue], [[[object coord]objectForKey:#"longitude"] floatValue]);
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [NSString stringWithFormat:#"%#",[object nome_obj]];
annotationPoint.subtitle = [NSString stringWithFormat:#"%#",[object address]];
[map addAnnotation:annotationPoint];
}
these are four type of object that I add on my map
when I enter inside this method
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView *view = nil;
if (annotation != mapView.userLocation) {
if ([[[arrayResults objectAtIndex:countPoint]iden]intValue] == 1){
view = [mapView dequeueReusableAnnotationViewWithIdentifier:#"type_one"];
if (!view) {
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"type_one"];
view.canShowCallout = YES;
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[aButton addTarget:self action:#selector(open:) forControlEvents:UIControlEventTouchUpInside];
[aButton setTag:countPoint+100];
view.rightCalloutAccessoryView = aButton;
view.image = [UIImage imageNamed:#"type_one.png"];
}
}
else if ([[[arrayResults objectAtIndex:countPoint]iden]intValue] == 2){
view = [mapView dequeueReusableAnnotationViewWithIdentifier:#"type_two"];
if (!view) {
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"type_two"];
view.canShowCallout = YES;
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[aButton addTarget:self action:#selector(open:) forControlEvents:UIControlEventTouchUpInside];
[aButton setTag:countPoint+100];
view.rightCalloutAccessoryView = aButton;
view.image = [UIImage imageNamed:#"type_two.png"];
}
}
else if ([[[arrayResults objectAtIndex:countPoint]iden]intValue] == 3){
view = [mapView dequeueReusableAnnotationViewWithIdentifier:#"type_three"];
if (!view) {
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"type_three"];
view.canShowCallout = YES;
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[aButton addTarget:self action:#selector(open:) forControlEvents:UIControlEventTouchUpInside];
[aButton setTag:countPoint+100];
view.rightCalloutAccessoryView = aButton;
view.image = [UIImage imageNamed:#"type_three.png"];
}
}
else if ([[[arrayResults objectAtIndex:countPoint]iden]intValue] == 4){
view = [mapView dequeueReusableAnnotationViewWithIdentifier:#"type_four"];
if (!view) {
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"type_four"];
view.canShowCallout = YES;
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[aButton addTarget:self action:#selector(openScheda:) forControlEvents:UIControlEventTouchUpInside];
[aButton setTag:countPoint+100];
view.rightCalloutAccessoryView = aButton;
view.image = [UIImage imageNamed:#"type_four.png"];
}
}
countPoint++;
}
The problem is that type of marker don't correspond with array element... but I don't understand.
That is if a marker has image "type_one", in the pop up it show "title" of type_four...it don't correspond
Your annotation needs to "know" what type it is so you can create the right kind of view in viewForAnnotation. Do so by subclassing MKPointAnnotation, adding an NSInteger value to it to store the array index.
See MKPointAnnotation add extra property, but you'll add an NSInteger property called index.
When creating your annotations, set this property:
for (int i = 0; i<arrayResults.count; i++)
{
object = [arrayResults objectAtIndex:i];
CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[object coord]objectForKey:#"latitude"] floatValue], [[[object coord]objectForKey:#"longitude"] floatValue]);
// MKMyPointAnnotation is your MKPointAnnotation subclass
MKMyPointAnnotation *annotationPoint = [[MKMyPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [NSString stringWithFormat:#"%#",[object nome_obj]];
annotationPoint.subtitle = [NSString stringWithFormat:#"%#",[object address]];
annotationPoint.index = i; // store the index
[map addAnnotation:annotationPoint];
}
Then in your viewForAnnotation, cast the annotation to your subclass, then dereference the type:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
{
MKMyPointAnnotation *myAnnotation = (MKMyPointAnnotation *)annotation;
object = [arrayResults objectAtIndex:myAnnotation.index]; // <-- your index property
switch ([[object iden] intValue])
{
case 1: // type one
.
.
.
}
.
.
.
}

Loading online data very slow difficult to PUSH

First of all I am running a Map page that just only show pins on map for every store. I was running only one pin on the map and it was fast after I put more than 25 pins it push very slow to the map page. What it is doing now at that process the app just load all data of the pin location (as I see in the target output) and then it push to the next screen. So please where would be my problem?
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"";
self.navigationItem.title = #"Mek";
response = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://kalkatawi.com/mapLocation.php"]];
if(response!=nil) {
NSError *parseError = nil;
jsonArray = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingAllowFragments error:&parseError];
jsonArray1 = [[NSMutableArray alloc] init];
jsonArray2 = [[NSMutableArray alloc] init];
jsonArray3 = [[NSMutableArray alloc] init];
for(int i=0;i<[jsonArray count];i++)
{
name = [[jsonArray objectAtIndex:i] objectForKey:#"name"];
longitude = [[jsonArray objectAtIndex:i] objectForKey:#"longitude"];
latitude = [[jsonArray objectAtIndex:i] objectForKey:#"latitude"];
[jsonArray1 addObject:name];
[jsonArray2 addObject:longitude];
[jsonArray3 addObject:latitude];
self.locationMap.delegate = self; //set delegate before adding annotations
CLLocationCoordinate2D annotationCoord;
for (int i=0; i < [jsonArray count]; i++)
{
NSDictionary *annotationDictionary = [jsonArray objectAtIndex:i];
name = [annotationDictionary objectForKey:#"name"];
annotationCoord.latitude
= [[annotationDictionary objectForKey:#"longitude"] doubleValue];
annotationCoord.longitude
= [[annotationDictionary objectForKey:#"latitude"] doubleValue];
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = name;
annotationPoint.subtitle = [NSString stringWithFormat:#"%f %f", annotationPoint.coordinate.latitude, annotationPoint.coordinate.longitude];
[self.locationMap addAnnotation:annotationPoint];
//------------------------//
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(annotationPoint.coordinate, 50000, 50000);
[self.locationMap setRegion:[self.locationMap regionThatFits:region] animated:YES];
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
lat = locationManager.location.coordinate.latitude;
lon = locationManager.location.coordinate.longitude;
}
}
}
else {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"You are not connected to internet" message:#"Please check the internet connection" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
if(annotation != locationMap.userLocation)
{
static NSString *defaultPinID = #"myPin";
pinView = (MKAnnotationView *)[locationMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.image = [UIImage imageNamed:#"pinpinpin.png"];
pinView.canShowCallout = YES;
pinView.enabled = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = infoButton;
}
return pinView;
}
SImple way is load data in background thread, and then when data is fully load display it on the map. You can do this in any of view controller, means you can do it in parent view controller and when you got response then update on map view controller.
Or on view did load method load data in background and update it when its load. This approach will not hold your UI. You can use blocks like this
dispatch_async(queue, ^{
//load data from server
dispatch_async(dispatch_get_main_queue(), ^{
//Update map
});
});

Detail disclosure send data from custom annotation

I have pins showing on a map with data from a JSON string from a db. I set the id of the pin (defined in a custom class) but I need to pass the ID to a action when pressing the detail disclosure button.
It will then open a new view with some information on that pin (via a database and it will lookup the row id and return the data, not sure how im going to do that just yet)
This is the code:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[spinner stopAnimating];
// json parsing
results = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
NSMutableArray * locations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
CustomAnnotation * myAnn;
NSArray *pins = mapView.annotations;
if ([pins count])
{
[mapView removeAnnotations:pins];
}
/* loop through the array, each key in the array has a JSON String with format:
* title <- string
* strap <- string
* id <- int
* date <- date
* lat <- floating point double
* long <- floating point double
* link <- string
*/
int i;
for (i = 0; i < [results count]; i++) {
//NSLog(#"Result: %i = %#", i, results[i]);
//NSLog(#"%#",[[results objectAtIndex:i] objectForKey:#"long"]);
myAnn = [[CustomAnnotation alloc] init];
location.latitude = (double)[[[results objectAtIndex:i] objectForKey:#"lat"] doubleValue];
location.longitude = (double)[[[results objectAtIndex:i] objectForKey:#"long"] doubleValue];
myAnn.coordinate = location;
myAnn.title = [[results objectAtIndex:i] objectForKey:#"title"];
myAnn.subtitle = [[results objectAtIndex:i] objectForKey:#"strap"];
myAnn.pinId = [[results objectAtIndex:i] objectForKey:#"id"];
NSLog(#"id: %i", myAnn.pinId);
[locations addObject:myAnn];
//NSLog(#"%i", [[results objectAtIndex:i] objectForKey:#"lat"]);
}
[self.mapView addAnnotations:locations];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
static NSString *s = #"ann";
MKAnnotationView *pin = [mapView dequeueReusableAnnotationViewWithIdentifier:s];
if (!pin) {
pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:s];
pin.canShowCallout = YES;
//pin.image = [UIImage imageNamed:#"pin.png"];
pin.calloutOffset = CGPointMake(0, 0);
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[button addTarget:self
action:#selector(viewDetails) forControlEvents:UIControlEventTouchUpInside];
pin.rightCalloutAccessoryView = button;
}
return pin;
}
-(void)viewDetails{
NSLog(#"press");
}
seems to me that you wish to detect which annotation is selected or its accessory view is clicked.
use the following method
-(void) mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
available to detect the callout tap action. But rather than setting the tag of button, tag the mkannotationView which you will provide for display of you annotation
-(MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
Some of the best tutorials are
http://www.raywenderlich.com/21365/introduction-to-mapkit-in-ios-6-tutorial

Tapping on MKAnnotationView doesn't call didSelectAnnotationView delegate

Take a look at this code and see if you can help me fixing it:
- (void)viewDidLoad
{
//Initialize the array and add annotations for the location on the map
annotations = [[NSMutableArray alloc] init];
CustomAnnotation *annotation;
CLLocationCoordinate2D coordinate;
//1
coordinate.latitude = 25.220390105797264;
coordinate.longitude = 55.28095199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = #"123";
[annotations addObject:annotation];
//2
coordinate.latitude = 25.218880105797264;
coordinate.longitude = 55.27992199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = #"117";
[annotations addObject:annotation];
//3
coordinate.latitude = 25.219280105797264;
coordinate.longitude = 55.28052199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = #"118";
[annotations addObject:annotation];
//4
coordinate.latitude = 25.219680105797264;
coordinate.longitude = 55.28052199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = #"119";
[annotations addObject:annotation];
//5
coordinate.latitude = 25.219980105797264;
coordinate.longitude = 55.28095199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = #"120";
[annotations addObject:annotation];
//6
coordinate.latitude = 25.220380105797264;
coordinate.longitude = 55.28115199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = #"121";
[annotations addObject:annotation];
//7
coordinate.latitude = 25.220350105797264;
coordinate.longitude = 55.28105199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = #"122";
[annotations addObject:annotation];
//8
coordinate.latitude = 25.215050105797264;
coordinate.longitude = 55.28105199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = #"124";
[annotations addObject:annotation];
//9
coordinate.latitude = -35.44138;
coordinate.longitude = -71.66208;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = #"125";
[annotations addObject:annotation];
//10
coordinate.latitude = -35.44138;
coordinate.longitude = -71.66208;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = #"126";
[annotations addObject:annotation];
//Set the region and zoom factor of the map view
MKCoordinateRegion region;
region.span.latitudeDelta = 0.01f;
region.span.longitudeDelta = 0.01f;
region.center.latitude = 25.216050105797264;
region.center.longitude = 55.27905199798584;
[sheikhZayedRoadMapView addAnnotations:annotations];
[sheikhZayedRoadMapView setRegion:region];
//[siteMapView.layer setCornerRadius:5.0];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id <MKAnnotation>)annotation
{
NSLog(#"Annotation Class: %#", [annotation class]);
static NSString * const kPinAnnotationIdentifier = #"PinIdentifier";
MKAnnotationView *annotationView;
Myriadproregular *annotationIndexLabel;
//CustomAnnotation *customAnnotation =nil
annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:kPinAnnotationIdentifier];
if (!annotationView) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kPinAnnotationIdentifier];
annotationIndexLabel = [[Myriadproregular alloc] initWithFrame:CGRectMake(0, 3, 25 , 20)];
annotationIndexLabel.font = [UIFont boldSystemFontOfSize:12];
[annotationIndexLabel setBackgroundColor:[UIColor clearColor]];
[annotationIndexLabel setTextColor:[UIColor whiteColor]];
[annotationIndexLabel setTextAlignment:UITextAlignmentCenter];
[annotationView addSubview:annotationIndexLabel];
annotationView.canShowCallout = YES;
annotationView.calloutOffset = CGPointMake(-5, 5);
}else {
//Get the label if exists
for (UIView *labelView in annotationView.subviews) {
if ([labelView isKindOfClass:[UILabel class]]) {
annotationIndexLabel = (Myriadproregular *) labelView;
break;
}
}
}
if ([annotation isKindOfClass:[MKUserLocation class]]) {
[annotationView setImage:[UIImage imageNamed:#"map_notify_bg.png"]];
}else {
CustomAnnotation *customAnnotation = (CustomAnnotation *) annotation;
[annotationIndexLabel setText:customAnnotation.annotationIndex];
[annotationView setImage:[UIImage imageNamed:#"ico_inspector.png"]];
}
return annotationView;
}
Problem is:
I am not getting didSelectAnnotationView delegate method called, when I tap on the custom image provided to MKAnnotationView.
Any kind of help will be appreciated.
Thanks
[annotationView setCanShowCallout:NO]
This solved my problem, because I didn't want a callout on click of a pin, but I wanted to call the didSelectAnnotationView delegate to be called.
Thanks
Are you giving your annotations a title property? Are you sure that [annotationView setCanShowCallout:YES] is set properly?

New PList Retrieval Code Prevents MKMapView Delegate Method From Being Called (iOS)

I added a plist database to store information for annotations in a MKMapView. Once I implemented the code to grab the information, my delegate methods are no longer being called.
The code I added was:
- (void)viewDidLoad
{
NSMutableArray *annotations = [[NSMutableArray alloc]init];
NSString *path = [[NSBundle mainBundle] pathForResource:#"MillersStores" ofType:#"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
NSArray *anns = [dict objectForKey:#"Root"];
for(int i = 0; i < [anns count]; i++) {
float realLatitude = [[[anns objectAtIndex:i] objectForKey:#"Latitude"] floatValue];
float realLongitude = [[[anns objectAtIndex:i] objectForKey:#"Longitude"] floatValue];
MillersLocations *myAnnotation = [[MillersLocations alloc] init];
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = realLatitude;
theCoordinate.longitude = realLongitude;
myAnnotation.coordinate = theCoordinate;
myAnnotation.title = [[anns objectAtIndex:i] objectForKey:#"Title"];
myAnnotation.subtitle = [[anns objectAtIndex:i] objectForKey:#"Address"];
[mapView addAnnotation:myAnnotation];
[annotations addObject:myAnnotation];
[myAnnotation release];
}
}
And this is one of delegate method that's no longer being called is:
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MKPinAnnotationView *pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"MillersAnnotation.png"]];
pinView.leftCalloutAccessoryView = leftIconView;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = rightButton;
return pinView;
}
I have another delegate method in there that also zooms into the User's Location that's not being called either, as well as the calloutAccessoryControlTapped method that's no longer being called.
I know it has something to do with the new code, but I'm confused as to how to even debug this because it's not giving me errors and I can't log it because the entire methods aren't even being called. When I get rid of the new code, the old code works fine...What is it in the new code that negates the old code?
It sounds like the map view's delegate property is not set.
Did the old code contain this line:
mapView.delegate = self;
Add that to viewDidLoad or, in IB, connect the map view's delegate outlet to File's Owner.

Resources