Note that there are some explanatory texts on larger screens.

plurals
  1. POUIButton event not handled 1% of the time: who should I blame in my responder chain?
    primarykey
    data
    text
    <p>My application tends to sometimes lose track of what responder should handle a touch event.</p> <p>My situation:</p> <ul> <li>a XIB file defining 3 views: <ul> <li>one view as the File's Owner's view</li> <li>2 extra views that are added to the view hierarchy programmatically</li> </ul></li> <li>One of the subview (SubviewA) has a <code>UIButton</code>, configured to send the <code>myAction:</code> selector to the <code>FirstResponder</code> when a "Touch Up Inside" event is detected</li> <li>SubviewA knows how to handle <code>myAction:</code></li> </ul> <p>99% of the time, everything goes fine. When the user taps the button, SubviewA takes care of the <code>myAction:</code> message and everything's fine. But from times to times, users complain that the button "freezes" and I actually reproduced it myself a couple of times without being able to find a clear scenario to make it happen on demand.</p> <p>My investigation so far is:</p> <ul> <li>when nothing happens when tapping the button: <ul> <li>my button detects the tap cause it gets highlighted when pressed</li> <li><code>myAction:</code> is not called on SubviewA</li> <li>the rest of the UI remains responsive</li> </ul></li> </ul> <p>The code I'm talking about is some legacy code I'm trying to fix. Having a view responding to an event for one of its subviews sounds like a weird architecture to me. So far, I've always used the File's Owner to take care of touch events so I pointed out the Responder Chain to be the ideal responsible for the bug. But I can't find why! From my understanding, as the button doesn't know how to handle the message and has no view controller attached to it, it should forward it to its superview (ButtonA, that knows how to handle it)!</p> <p>My questions are :</p> <ul> <li>any idea on where the bug might come from? (responder chain?)</li> <li>any comment on whether a view should handle its button behaviors itself or if a view controller should do it?</li> </ul> <p>Edit: I have an idea on how to fix the bug: wire the button action straight to SubviewA rather than using FirstResponder within Interface Builder. The reason why I posted this question is to try to understand why is the responder chain not working from times to times.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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