开发者

Search suggestions for text in UITextField, iPhone

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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜