Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

johnmerlino

macrumors member
Original poster
Oct 22, 2011
81
0
I looked at several tutorials and they all show the same way of doing this by creating a uibutton and then setting to the annotation but when I do it:

Code:
 MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
        newAnnotation.pinColor = MKPinAnnotationColorGreen;
        newAnnotation.animatesDrop = YES;
        newAnnotation.canShowCallout = YES;
        
        UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton setTitle:annotation.title forState:UIControlStateNormal];
        [newAnnotation setRightCalloutAccessoryView:rightButton];
        
        return newAnnotation;

everything displays but the button

thanks for response
 
I'm no expert yet myself, but I'm developing an app with MapKit right now myself. I can't find anything that I would say is obviously wrong with the code you posted, so it's possible the problem is elsewhere.

I did see 2 things that I would investigate though:

Code:
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];

#1 your reuseIdentifuer is being set to nil. I'm not sure that this would cause the exact problem you're having. It might not cause any problems if you're only trying to display one annotation. I would expect there to be problems if you were trying to display different types of annotations without assigning each type an identifier. But that is something I would look into.

Code:
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton setTitle:annotation.title forState:UIControlStateNormal];
        [newAnnotation setRightCalloutAccessoryView:rightButton];

#2 There isn't any place (that I can see) where you've assigned a selector to your button. I would not expect this to keep the button from being displayed. I would expect the button to be displayed and that nothing would happen when you touch it. I could be wrong.

Those are just some things that raised some questions for me. It's hard to say more without seeing more code.
 
I'm no expert yet myself, but I'm developing an app with MapKit right now myself. I can't find anything that I would say is obviously wrong with the code you posted, so it's possible the problem is elsewhere.

I did see 2 things that I would investigate though:

Code:
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];

#1 your reuseIdentifuer is being set to nil. I'm not sure that this would cause the exact problem you're having. It might not cause any problems if you're only trying to display one annotation. I would expect there to be problems if you were trying to display different types of annotations without assigning each type an identifier. But that is something I would look into.

Code:
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton setTitle:annotation.title forState:UIControlStateNormal];
        [newAnnotation setRightCalloutAccessoryView:rightButton];

#2 There isn't any place (that I can see) where you've assigned a selector to your button. I would not expect this to keep the button from being displayed. I would expect the button to be displayed and that nothing would happen when you touch it. I could be wrong.

Those are just some things that raised some questions for me. It's hard to say more without seeing more code.

I had the button instantiation in the wrong if statement.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.