Reputation:
I want to implement a same autocomplete email functionality as showing in above screen in my UITextField
Please suggest
Upvotes: 3
Views: 1671
Reputation: 16553
What kingOfBliss said is the correct way. anyhow i will provide you some logic of the code. Try tis code
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
for(NSString *particularEmail in arrayContainsAllEmailAddress)
{
NSString *firstLetter = @"";
NSInteger stringlen=[string length];
if(particularEmail.length >= stringlen)
{
firstLetter = [particularEmail substringToIndex:stringlen];
}
if(firstLetter.length > 0)
{
if([string.uppercaseString isEqualToString:firstLetter.uppercaseString])
{
[tableArray addObject:particularEmail];
//tableArray is the array which u will load into the tableview. This contains the emails that matches your search name.
}
}
}
// Add your tableArray into UITableView
}
Upvotes: 0
Reputation: 15115
Do as follows, 1)store the emails 2)When the user starts type the text in textField search the stored valu and display the values in UITableView
You should use the following delegate of UITextField
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
Upvotes: 1