EddyBorja / MLPAutoCompleteTextField

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

can't click on suggestion #16

Closed wiistriker closed 10 years ago

wiistriker commented 10 years ago

I implement simple datasource for autocomplete list and show suggestions, but when i try to select one of the suggestion it do nothing.

I also try to implement some delegate methods like:

- (void)autoCompleteTextField:(MLPAutoCompleteTextField *)textField
  didSelectAutoCompleteString:(NSString *)selectedString
       withAutoCompleteObject:(id<MLPAutoCompletionObject>)selectedObject
            forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"select: %@", selectedString);
}

Nothing happens.

http://s1.ipicture.ru/uploads/20131008/At8TrUtS.png

akaru commented 10 years ago

I have the same problem. I think it's because using MLPAutocomleteTextField inside UITableView, so all touch events are intercepted by tableview.

EddyBorja commented 10 years ago

akaru has the right idea.

The problem is actually that the tableview of autocomplete suggestions is a subview of the UITableViewCell, but it lies outside the touchable area of the UITableViewCell, so it won't receive touch events, but it's still visible because the cell doesn't clip it's bounds.

A quick way to get around this problem is to not use the drop down style autocomplete table, instead use the keyboard accessory version.

kevinseelbach commented 10 years ago

I had the same problem, but I had forgot to set the field's delegate as itself, as in the example:

    self.autoCompleteField.delegate = self;
    self.autoCompleteField.autoCompleteDataSource = self;
    self.autoCompleteField.autoCompleteDelegate = self;

Whether it was a dropdown table or keyboard accessory didn't seem to make a difference.

EddyBorja commented 10 years ago

Are you saying you can't select items from the keyboard accessory either when the textfield is inside a tableview cell? If so, then that's the first time I've heard that issue.

kevinseelbach commented 10 years ago

I had a problem where the protocol method (which I copied from the demo) was not being called, but realized I forgot to set the delegates; I'm new to iOS but think that was my problem. The drop down appeared, the keyboard accessory appeared, but the NSLog statements were not called.

— Sent from Mailbox for iPhone

On Thu, Nov 28, 2013 at 3:00 PM, Eddy Borja notifications@github.com wrote:

Are you saying you can't select items from the keyboard accessory either when the textfield is inside a tableview cell? If so, then that's the first time I've heard that issue.

Reply to this email directly or view it on GitHub: https://github.com/EddyBorja/MLPAutoCompleteTextField/issues/16#issuecomment-29485093

bryanlogan commented 10 years ago

Kevin, I'm seeing something similar. It started happening once I assigned the delegate for the MLPAutoCompleteTextField to the view controller (because I needed to do some stuff to handle the keyboard covering things up). Once I did this though, the UITableView doesn't receive the row selected event. The table does go away, but the field isn't updated.

I might be missing a [super] or something. I'll investigate more.

mikumi commented 10 years ago

I think this issue has been fixed in https://github.com/EddyBorja/MLPAutoCompleteTextField/pull/30 as well. The screenshot wiistriker has uploaded shows a UITableView.

boazin commented 9 years ago

I seem to be having the same issue. Dropdown is not clickable when the textfield is inside a UITableViewCell - do I still have to use keyboard accessory?

JeanMeche commented 9 years ago

+1 I encounter the same problem when the textfield is in a UITableView (not a cell).

jbiscarri commented 8 years ago

I solved It by subclassing my UITableViewCell:

#import "AutoCompleteTableViewCell.h"

@interface AutoCompleteTableViewCell()
@property (nonatomic, assign) BOOL selectedCell;
@end

@implementation AutoCompleteTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectedCell = NO;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
{
    UIView* hitView = [super hitTest:point withEvent:event];
    if (hitView != nil)
    {
        [self.superview bringSubviewToFront:self];
    }
    return hitView;
}

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event
{
    CGRect rect = self.bounds;
    BOOL isInside = CGRectContainsPoint(rect, point);
    if(!isInside)
    {
        for (UIView *view in self.subviews)
        {
            isInside = CGRectContainsPoint(view.frame, point);
            if(isInside)
                break;
        }
    }
    if (!self.selectedCell) {
        self.selectedCell = YES;
        id view = [self superview];
        while (view && [view isKindOfClass:[UITableView class]] == NO) {
            view = [view superview];
        }
        UITableView *tableView = (UITableView *)view;
        NSIndexPath *indexPath = [tableView indexPathForCell:self];
        [tableView.delegate tableView:tableView didSelectRowAtIndexPath:indexPath];
    }
    return isInside;
}