button on callout bubble doesnt display on mapkit

Discussion in 'iOS Programming' started by johnmerlino, May 9, 2012.

  1. johnmerlino macrumors member

    Joined:
    Oct 22, 2011
    #1
    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
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Which tutorials? When referring to third-party resources, it's a good idea to provide as much information about them as possible. In this case, you probably should provide some links. Thanks.
     
  3. TheWatchfulOne macrumors 6502

    Joined:
    Jun 19, 2009
    #3
    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.
     
  4. johnmerlino thread starter macrumors member

    Joined:
    Oct 22, 2011
    #4
    I had the button instantiation in the wrong if statement.
     

Share This Page