I have a UITextField as follows.
UITextField *fromText = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 150, 33)];
When user types in this UITextField, I want to give user suggestions of possible text from a collection of known NSString's stored in NSMutableArray. Size of this NSMutable array varies between 0-100.
what will be the best way to do this开发者_开发知识库?
Thanks for any help in advance..
I would start with a simple range search on NSString
for example: As I am about to type home, after 3 characters run this:
NSString *searchFor = @"hom";
NSRange range;
for (NSString *string in stringList)
{
range = [string rangeOfString:searchFor];
if (range.location != NSNotFound)
{
NSLog (@"suggest '%@' found in '%@'.", searchFor, string);
}
}
精彩评论