How do I get a UITableView header view to come before the table cells in the responder chain?
-
I have a rather large table header view above my table view. I have a number of subviews in that header view. I am doing something a bit nonstandard where I am "sticking" some of those subviews (but not all) at the top of the table view. My problem is that although visually the table view cells pass under the sticky table header subviews, it seems that the table view cells are "above" the table header view in terms of touch response. (For example: I have a button that is a subview of the table header view. When there are no cells underneath the button, the button works great and responds to touches. However, when the user scrolls the table view so that there are cells underneath the button, a touch on the button actually selects a hidden cell rather than push the button.) Can anyone give advice on how to "raise" the table header view above the table view cells, so that its subviews get first shot at touch handling? I am using a table header view rather than a section header view due to the fact that I only want some of the subviews to stick (letting the others scroll up off the screen as usual). One of the subviews also can be expanded (and that expansion is animated) - to a height that is even bigger than the entire height of the screen. For these reasons, I didn't think using a section header view would be feasible. (If it is, please let me know, as I know that section header views are "above" table cells when it comes to touch response.)
-
Answer:
The UIView documentation (for hitTest:withEvent:) says, Points that lie outside the receiverâs bounds are never reported as hits, even if they actually lie within one of the receiverâs subviews. This can occur if the current viewâs clipsToBounds property is set to NO and the affected subview extends beyond the viewâs bounds. The table header view appears above the first cell and, when you scroll down, moves up and off the top of the screen. If you have subviews of the table header view that you are manipulating to stick to the top of the table view, chances are they are well outside the table header view's bounds. (You probably didn't think you were going to run into a problem since clipsToBounds is by default NO.) In other words, this isn't a problem of responder chain order; this is a problem of view geometry. Your views aren't receiving touch events at all because the parent view has scrolled off the screen. Rewriting touch handling, even with gesture recognizers, is very bad idea. (Unless you have time to handle all the edge cases and also the Accessibility API.) You should split your content: the part that scrolls away should be the table header view, and the part that should stick to the top of the table should be a custom section header view. If something needs to expand and cover the entire table, it should be implemented as a new view (you can animate the transition so it looks like the same view is growing larger).
Benjamin Ragheb at Quora Visit the source
Other answers
I would try disabling selection on the table view, and reimplementing selection using a UIGestureRecognizer. Furthermore I'd use the UIGestureRecognizerDelegate protocol to conditionally block the recognizer if necessary.
Chris Hinkle
Related Q & A:
- How do I get a value from a JObject?Best solution by Stack Overflow
- How can I get a good deal at a luxury resort?Best solution by lastminute.com
- How do I remove a firewall to view a webcam?Best solution by Yahoo! Answers
- How do I get my Yahoo e-mail to come in under Outlook Express?Best solution by Yahoo! Answers
- How can I get a text alert when I get an email?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.