EddyBorja / MLPAutoCompleteTextField

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

AutoCompleteSource protocol #64

Open woniesong92 opened 9 years ago

woniesong92 commented 9 years ago

From the readme, I implemented autoCompleteTextField method, but I still get the following error message.

*\ Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An autocomplete datasource must implement either autoCompleteTextField:possibleCompletionsForString: or autoCompleteTextField:possibleCompletionsForString:completionHandler:'

AutoCompleteDataSource.h

#import "MLPAutoCompleteTextFieldDataSource.h"

@interface StationAutoCompleteSource : NSObject <MLPAutoCompleteTextFieldDataSource>

- (void)autoCompleteTextField:(MLPAutoCompleteTextField *)textField
 possibleCompletionsForString:(NSString *)string
            completionHandler:(void(^)(NSArray *suggestions))handler;

@property (strong, nonatomic) NSArray *allCountries;
@property (strong, nonatomic) NSArray *countryObjects;
@property (assign) BOOL testWithAutoCompleteObjectsInsteadOfStrings;

@end

AutoCompleteDataSource.m

- (void)autoCompleteTextField:(MLPAutoCompleteTextField *)textField
possibleCompletionsForString:(NSString *)string
completionHandler:(void (^)(NSArray *))handler
{
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    dispatch_async(queue, ^{
        NSArray *completions;
        completions = [self allCountries];
        handler(completions);
    });
}
gramx commented 9 years ago

I am not sure if this is the same issue I had, but I got that error and the issue was I was not setting my data source delegate on the field.

Something in the controller or view:

self.fieldName.autoCompleteDataSorce = self; self.fieldName.autoCompleteDelegate = self; self.fieldName.Delegate = self;

However, since I handled all my code in one field (probably not the best decision on my part) and you did not this exact code will not work for you, but maybe will point you in a helpful direction.

hardikamal commented 9 years ago

Hi @woniesong92 any solution found to the issue???

anthonybarouch commented 9 years ago

hi,

I have the same issue .. :(

tkram01 commented 8 years ago

having the same issue

SanjeetVerma commented 7 years ago

having the same issue got any luck?

dawesc commented 4 years ago

The problem is because it's now a weak property it no longer holds your data source object if you loose reference to it. You need to ensure that in your calling class you keep a strong reference to this object.