I’m trying to get the titleLabel string of a UIButton, but it’s logging as a CALayer… any suggestions?
//ADD TWT BUTTON
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.titleLabel.hidden = YES;
twitter_share.titleLabel.alpha = 0;
twitter_share.tag = 20;
[twitter_share setTitle:@"test!" forState:UIControlStateNormal];
UITapGestureRecognizer *tap_twt = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinButtonTap:)];
tap_twt.numberOfTapsRequired = 1;
[twitter_share addGestureRecognizer:tap_twt];
[tap_twt release];
[annotationView addSubview:twitter_share];
- (void) handlePinButtonTap:(UITapGestureRecognizer *)gestureRecognizer {
UIButton *btn = (UIButton *) gestureRecognizer.view;
MKAnnotationView *av = (MKAnnotationView *)[btn superview];
id<MKAnnotation> ann = av.annotation;
NSLog(@"handlePinButtonTap: ann.title=%@", ann.title);
NSString *testBtn = [NSString stringWithFormat:@"%@", [btn titleLabel]];
NSLog(@"handlePinButtonTap: btn title=%@", testBtn);
}
Log:
handlePinButtonTap: btn title=<UIButtonLabel: 0x70a14d0; frame = (0 3; 29 22); text = 'test!'; clipsToBounds = YES; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x70a6930>>
You must have a double-release error somewhere, which means your
titlestring has been deallocated too soon, and its memory has been taken by another object (theCALayer). Search forNSZombieEnabledor justxcode zombiesand you should be able to turn on zombie detection which will give you more information.