EddyBorja / MLPAutoCompleteTextField

UITextfield subclass with autocomplete menu. For iOS.
Other
1.21k stars 222 forks source link

AutoCompleteTableView loses user interaction when displayed over a sibling table cell #82

Open robdigital opened 9 years ago

robdigital commented 9 years ago

I'm using MLPAutoComplete TextFields in my project, in several textfields in dynamic table cells. It works perfectly when the cell's row is large enough to fit the entire AutoCompleteTableView (scrollable list of suggestions). However, if the row height is smaller than the auto suggestion window, the user interaction is not being picked up by the 'scrollable auto suggstion window' and instead of scrolling through the suggestions, it is making my tableview scroll.

I've played around with z indexes, bringing the textfield and autocomplete views to the front of super, which doesn't make any difference.

I've also tried setting EnableUserInteraction = NO on the tableview after the autocomplete is triggered, which only has the effect of making the scrollview unresponsive even though its own property of EnableUserInteraction is still set to YES.

I'm thinking that because I also use TPKeyboardAvoiding in my project, that it is somehow complicating the issue.

See the image of one example (it happens on all my views), in this particular example, the table has a header cell on top, then the following are dynamic cells. You can see in the image the hard black line (between tara and Clagary) that is the physical cutoff of the scrollability. i.e. touch above the line and autocomplete scrolls, touch below and whole table scrolls.

issuewithdropdown

Second picture to further detail working and broken interface. issuewithdropdown2

And this also happens in the dynamic cells, not just header. Here is the next example. issuewithdropdown3

theoriginalgri commented 9 years ago

To work around this, you can assign the autoCompleteParentView to the self.view (the parent of your UITableViewController) and change the autoCompleteTableOriginOffset to the mapped values. This might not work when scrolling is involved.

For example:

// Parent correction
textField.autoCompleteParentView = self.view;

// Offset correction
CGPoint pt = [textField convertPoint:CGPointMake(0, textField.frame.origin.y) toView:self.view];
textField.autoCompleteTableOriginOffset = CGSizeMake(0, pt.y);
hamishcundy commented 9 years ago

I'm having the same issue - however I can't find the autoCompleteParentView field. Are you sure thats the correct name?

theoriginalgri commented 9 years ago

OH! I am sorry!

One of our developers added this property and I did not check for that.

https://github.com/endiosGmbH/MLPAutoCompleteTextField/commit/ef3243a6c808a47121407baff7d55892e5924fb6

It might be good to prepare a pull request for that :hushed:

zabolotiny commented 8 years ago

Hi, I have the same issue. After some investigation i have such info regarding the issue:

  1. This happens only when autolayout is active.
  2. Interaction is lost only on the part of the autocomplete table view http://prntscr.com/9h4jgy Unfortunately i can't find a solution :( Any suggestions to solve that problem?
emartinson commented 8 years ago

@theoriginalgri Thank you!!! Your solution with parentView worked perfect!!!

RyogaK commented 8 years ago

+1

t4ec commented 8 years ago

@theoriginalgri could you please merge the changes you mentioned regarding parentView? It would be great to have it by default in pod.

Thank you beforehand.

pavankataria commented 8 years ago

@theoriginalgri @EddyBorja This still doesn't work for me... when I set the parent view to self.view, that is the tableview's superview, the bottom half of the autocomplete list still cannot accept touches other than the top half.. Could someone assist further please? Thank you

ekhademi commented 6 years ago

I have tried to solve a more general problem: Problem: The autoCompleteTableView being outside of the parent view of the MLPAutoCompleteTextField, thus not responding to touch events. Solution: Expanding the hittable area of MLPAutoCompleteTextField's parent view like described in this link (the hit test considers the autoCompleteTableView's boundaries): https://stackoverflow.com/questions/11770743/capturing-touches-on-a-subview-outside-the-frame-of-its-superview-using-hittest The Swift approach for the parent view looks something like this:

class MLPAutoCompleteTextFieldParentView: UIView {
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {

        if clipsToBounds || isHidden || alpha == 0 {
            return nil
        }

        for subview in subviews.reversed() {
            let subPoint = subview.convert(point, from: self)
            if let result = subview.hitTest(subPoint, with: event) {
                return result
            }
        }

        return nil
    }
}

I have tested this approach when the MLPAutoCompleteTextField is inside a tableView.