I'm having trouble capturing taps on a UIButton
that's a subview of a UIView
. Here's how my code is setup:
// in MyClass.m
@interface MyClass ()
@property (nonatomic, retain) UIButton *myButton;
@end
@implementation MyClass
@synthesize myButton;
- (void) buttonTapped:(id) sender {
NSLog(@"button tapped!");
}
- (id) initWithFrame:(CGRect)frame {
if (!(self = [super initWithFrame:CGRectZero]))
return nil;
myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[myButton setImage:[UIImage imageNamed:@"image.png"]
forState:UIControlStateNormal];
[myButton addTarget:self
action:@selector(buttonTapped:)
forControlEvents:UIControlEventTouchUpInside];
myButton.exclusiveTouch = YES;
myButton.frame = CGRectMake(100, 100, 100, 100);
[self addSubview:myButton];
return self;
}
- (void) dealloc {
[myButton release];
[super dealloc];
}
@end
The button appears in the view. The button color changes momentarily when I tap it. However the selector buttonTapped:
is never called. Any idea why?
How can I verify that buttonTapped:
is indeed a target of myButton?