Note that there are some explanatory texts on larger screens.

plurals
  1. POSubclassing MKPinAnnotationView
    primarykey
    data
    text
    <p>I'm creating my own annotation callout by subclassing MKPinAnnotationView. Everything works great, except for when I try to add buttons inside the new callout... the buttons are never called on touch... any idea why?</p> <p>Thanks in advance!</p> <p>Code is below: </p> <pre><code>- (id)initWithAnnotation:(id&lt;MKAnnotation&gt;)annotation reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]; if (self) { self.frame = CGRectMake(0.0f, 0.0f, 284.0f, 245.0f); self.backgroundColor = [UIColor clearColor]; UIImageView *callout_bkg = [[UIImageView alloc] init]; callout_bkg.image = [UIImage imageNamed:@"callout_bkg.png"]; callout_bkg.frame = CGRectMake(0, 0, 240, 110); [self addSubview:callout_bkg]; titleLabel_ = [[UILabel alloc] initWithFrame:CGRectMake(12.0f, 8.0f, 145.0f, 20.0f)]; titleLabel_.textColor = [UIColor whiteColor]; titleLabel_.textAlignment = UITextAlignmentLeft; titleLabel_.backgroundColor = [UIColor clearColor]; titleLabel_.font = [UIFont fontWithName:@"Geogrotesque" size:12]; [self addSubview:titleLabel_]; descLabel_ = [[UILabel alloc] initWithFrame:CGRectMake(12.0f, 30.0f, 180.0f, 40.0f)]; descLabel_.textColor = [UIColor grayColor]; descLabel_.textAlignment = UITextAlignmentLeft; descLabel_.backgroundColor = [UIColor clearColor]; descLabel_.numberOfLines = 15; descLabel_.font = [UIFont fontWithName:@"Geogrotesque" size:10]; [self addSubview:descLabel_]; communityLabel_ = [[UILabel alloc] initWithFrame:CGRectMake(125.0f, 8.0f, 60.0f, 20.0f)]; communityLabel_.textColor = [UIColor whiteColor]; communityLabel_.textAlignment = UITextAlignmentRight; communityLabel_.backgroundColor = [UIColor clearColor]; communityLabel_.font = [UIFont fontWithName:@"Geogrotesque" size:10]; [self addSubview:communityLabel_]; typeLabel_ = [[UILabel alloc] initWithFrame:CGRectMake(12.0f, 72.0f, 50.0f, 20.0f)]; typeLabel_.textColor = [UIColor whiteColor]; typeLabel_.textAlignment = UITextAlignmentLeft; typeLabel_.backgroundColor = [UIColor clearColor]; typeLabel_.font = [UIFont fontWithName:@"Geogrotesque" size:10]; [self addSubview:typeLabel_]; facebook_share = [[UIButton alloc] initWithFrame:CGRectMake(200, 17, 29, 27)]; facebook_share.backgroundColor = [UIColor clearColor]; [facebook_share setBackgroundImage:[UIImage imageNamed:@"btn_annotation_share_fb.png"] forState:UIControlStateNormal]; [facebook_share addTarget:self action:@selector(calloutAccessoryTapped) forControlEvents:UIControlStateNormal]; [self addSubview:facebook_share]; twitter_share = [[UIButton alloc] initWithFrame:CGRectMake(200, 44, 29, 28)]; twitter_share.backgroundColor = [UIColor clearColor]; [twitter_share setBackgroundImage:[UIImage imageNamed:@"btn_annotation_share_twitter.png"] forState:UIControlStateNormal]; [twitter_share addTarget:self action:@selector(calloutAccessoryTapped) forControlEvents:UIControlStateNormal]; [self addSubview:twitter_share]; } return self; } -(void)calloutAccessoryTapped { NSLog(@"TEST!"); } - (void)dealloc { [facebook_share release]; [twitter_share release]; [community_ release], community_ = nil; [communityLabel_ release], communityLabel_ = nil; [type_ release], type_ = nil; [typeLabel_ release], typeLabel_ = nil; [desc_ release], desc_ = nil; [descLabel_ release], descLabel_ = nil; [title_ release], title_ = nil; [titleLabel_ release], titleLabel_ = nil; [super dealloc]; } -(void)drawRect:(CGRect)rect { [super drawRect:rect]; titleLabel_.text = self.type; descLabel_.text = self.desc; communityLabel_.text = self.community; typeLabel_.text = self.title; [facebook_share addTarget:self action:@selector(test:) forControlEvents:UIControlStateNormal]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload