Подклассы MKPinAnnotationView - PullRequest
       19

Подклассы MKPinAnnotationView

0 голосов
/ 04 октября 2011

Я создаю свой собственный выноску аннотации путем создания подкласса MKPinAnnotationView. Все отлично работает, за исключением случаев, когда я пытаюсь добавить кнопки в новый вынос ... кнопки никогда не вызываются на ощупь ... есть идеи, почему?

Заранее спасибо!

Код ниже:

- (id)initWithAnnotation:(id<MKAnnotation>)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];
    }

1 Ответ

1 голос
/ 04 октября 2011

попробуйте с:

facebook_share = [UIButton buttonWithType:UIButtonTypeCustom];
facebook_share.frame = yourFrame;
...