Note that there are some explanatory texts on larger screens.

plurals
  1. POUIButton does not detect touch events when clicked
    text
    copied!<p>I've created a tableview that has custom cells (I've subclassed <code>UITableViewCell</code>). <br/>I'm creating several <code>UIButtons</code> in it. Declaring this in the .h file:</p> <pre><code>@property (nonatomic, strong) UIButton *myButton; </code></pre> <p>and this in the .m file:<br></p> <pre><code>myButton = [[UIButton alloc] initWithFrame:CGRectMake(-100.0, 285.0, 60.0, 30.0)]; myButton.titleLabel.font = [UIFont boldSystemFontOfSize:16.0]; myButton.backgroundColor = [UIColor clearColor]; [myButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; [myButton setTitle:@"text" forState:UIControlStateNormal]; [myButton addTarget:self action:@selector(myButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:myButton]; </code></pre> <p>I'm moving the cell to the right using <code>UIPanGestureRecognizer</code> and then the <code>UIButton</code> is revealed (notice that it is in a <strong>negative X index</strong>).<br>I can see it but it is not clickable (I guess it is not in the view any more).<br> Any suggestion about how to make it clickable?</p> <p>More details:<br> In the init of the cell, I'm doing:<br></p> <pre><code>UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; panGesture.delegate = self; [self.contentView addGestureRecognizer:panGesture]; </code></pre> <p>Then I implemented the gesture:</p> <pre><code>-(void)handlePanGesture:(UIPanGestureRecognizer *)sender { CGPoint translate = [sender translationInView:self.contentView]; CGRect currentFrame = self.contentView.frame; switch ([sender state]) { case UIGestureRecognizerStateChanged: currentFrame.origin.x = translate.x; self.contentView.frame = currentFrame; break; default: break; } } </code></pre> <p>When the frame moves to the right - the button is revealed. But not clickable...</p>
 

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