user1592698
user1592698

Reputation: 98

Search function with automatic suggestions

I want my user to be able to, when they are searching that under the text field they get choices. As en example if I am searching apple then under i get choices like apple, apple store, etc.I am very new to this topic. Huge thanks in advance!

Upvotes: 1

Views: 174

Answers (1)

MadhuP
MadhuP

Reputation: 2019

You Can Do, If The Data is With You

if([textField.text length] > 0 || textField.text != nil)
    {
        for(int i = 0; i < [array1 count]; i++)
        {
                NSString *strName = [NSString stringWithFormat:@"%@", [[array1 objectAtIndex:i] valueForKey:@"value"]];         
                if([[strName lowercaseString] hasPrefix:[newString lowercaseString]])
                {
                    [array2 addObject:[array1 objectAtIndex:i]];
                }
            }
        }
    }

Add This Code in

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

Add A UITableView below your UITextField According To your Frame. Display the Array2 Details in UITableView.

Try This it May Helps You

Upvotes: 4

Related Questions