Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to catch any touch event on a UIButton that is a subview of a UITableView
    text
    copied!<p>In my app I use an overlay style of presenting help information. Tapping an Info-button in the toolbar overlays a <code>UIButton</code> on top of whatever view is currently my main view. It draws an image with help text and arrows pointing to various user interface elements in the current navigation bar and toolbar.</p> <p>Tapping the Info-button again disposes the <code>UIButton</code>, but I also want to get rid of it if the user touches this overlaid button. It works perfectly except for my main view controller, which is a <code>UITableViewController</code>.</p> <p>What I do is create the <code>UIButton</code> and add it as a subview of the <code>UITableView</code> which is the only view in my main view controller. Then I set it to handle all touch events:</p> <pre><code>[[self masterInfoView] addTarget:self action:@selector(toggleMasterInfo:) forControlEvents:UIControlEventAllTouchEvents]; </code></pre> <p>The <code>UIButton</code> has the same size as the table view it now covers, and it goes away of I tap it, but if I make a scrolling gesture (tapping and holding down my finger inside it) the button does not see this as a touch event, instead the underlying table view handles it and scrolls its rows, moving the button along with it.</p> <p>Before moving to a <code>UIButton</code> I worked with a <code>UIView</code> and all kinds of gesture recognizers to achieve the same, as well as capturing the <code>UIResponder</code> events like <code>touchesBegan:withEvent:</code>, all with reasonable results but nothing perfect.</p> <p>It can not be that hard to make this work, what am I missing?</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