I have a button in CellView Cell, I need to respond to touch events. This is usually easy to solve with
[cell.playButton addTarget:self action:@selector(playButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
inside -tableView: cellForRowAtIndexPath:
The problem I am facing is that my button is inside a custom subclass of UITableViewCell and is also a subview of the view that I create inside this class.
eg:
UIView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; self.theView = view; [self addSubview:view]; [view release]; UIButton *playButton = [UIButton buttonWithType:UIButtonTypeCustom]; playButton.frame = CGRectMake(5, 5, 100, 30); [playButton setImage:[UIImage imageNamed:@"button_playvid.png"] forState:UIControlStateNormal]; [playButton setImage:[UIImage imageNamed:@"button_playvid_active.png"] forState:UIControlStateHighlighted]; self.playButton = playButton; [self.theView addSubview:playButton];
When a button is a subview of a view that I create in a custom UITableViewCell, the cell is highlighted instead of clicking the button, so the target that I set up in -tableView: cellForRowAtIndexPath is never called. Not sure why .. any help?
Thanks,
Joel
PS. I understand that there is probably no practical reason for creating a background view in the same way as it already is. This is just an example of the code that I use to explain my problem ..: D
Thanks for watching!
source share