Skip to content

Instantly share code, notes, and snippets.

@tetek
Created June 6, 2012 10:54
Show Gist options
  • Select an option

  • Save tetek/2881266 to your computer and use it in GitHub Desktop.

Select an option

Save tetek/2881266 to your computer and use it in GitHub Desktop.
SuggestionList - how to
//In your ViewController define a property with SuggestionsList instance
//in .h
@property(retain)SuggestionsList *suggList;
//in .m
@synthesize suggList = _suggList;
//initialize it with array of strings that contains suggestions you want to present
NSArray *array = [NSArray arrayWithObjects:@"Berlin",@"Warsaw",@"Wroclaw",@"Barcelona",nil];
self.suggList = [[[SuggestionsList alloc] initWithArray:array] autorelease];
//implement UITextFieldDelegate in you view controller and implement this method
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
//This method is called every time users type something in text field, so we need to update our suggestions here. Make it look like this:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
[_suggList showSuggestionsFor:textField shouldChangeCharactersInRange:range replacementString:string];
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment