Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8314093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:42:28+00:00 2026-06-08T20:42:28+00:00

The following code lets me auto suggest values typed into a UITextfield, by comparing

  • 0

The following code lets me auto suggest values typed into a UITextfield, by comparing it to an array of previously added string objects and show it in a UITableview.
This works fine, but only for a single word.

So now, can I modify the code in such a way, that after the user enters a comma, then starts typing again, I can search the same string array for suggestions again for the characters typed after the comma?

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

if (textField.tag == tagTextFieldTag)    //The text field where user types
{
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    autocompleteTableView.hidden = NO;   //The table which displays the autosuggest

        NSString *substring = [NSString stringWithString:textField.text];

        substring = [substring stringByReplacingCharactersInRange:range withString:string]; 

if ([substring isEqualToString:@""]) 
    {
        autocompleteTableView.hidden = YES; //hide the autosuggest table if textfield is empty
    }
        [self searchAutocompleteEntriesWithSubstring:substring];  //The method that compares the typed values with the pre-loaded string array

    }


return YES;
}

 - (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {

[autoCompleteTags removeAllObjects];

for(Tag *tag3 in tagListArray)   //tagListArray contains the array of strings

 //tag3 is an object of Tag class, which has a single attribute called 'text'

{
    NSString *currentString = tag3.text;
    NSRange substringRange = [currentString rangeOfString:substring];
    if(substringRange.location ==0)
    {
        [autoCompleteTags addObject:currentString];
    }
}

[autocompleteTableView reloadData];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:42:31+00:00Added an answer on June 8, 2026 at 8:42 pm

    You can do it like this,

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 
    {
    
      if (textField.tag == tagTextFieldTag)    //The text field where user types
      {
        textField.autocorrectionType = UITextAutocorrectionTypeNo;
        autocompleteTableView.hidden = NO;   //The table which displays the autosuggest
        NSArray *autoComplete = [textField.text componentsSeparatedByString:@","];
        NSString *substring = [NSString stringWithString:[autoComplete lastObject]];
       if ([substring isEqualToString:@""]) 
        {
            autocompleteTableView.hidden = YES; //hide the autosuggest table if textfield is empty
        }
            [self searchAutocompleteEntriesWithSubstring:substring];
    
        }
    
     return YES;
    }
    

    this method works like,

    • componentsSeparatedByString seperates the textFields text by , and give it as an NSArray
    • lastObject takes the last object from that array. If it is @”” no searching otherwise searches for an matching element.

    Hope this will help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say we have the following code: #include <iostream> #include <string> struct A {
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
Lets say I have the following code public static string GetXMLValue() { XDocument settingsFile
I have the following code which lets the user plot two points on a
Lets assume we have the following code: abstract class Base1 { protected int num;
Lets say that I have the following code: public class Shelter<A extends Animal, B
Lets say I have the following code: import collections d = collections.OrderedDict() d['foo'] =
Lets say that I'm trying to create a new process with the following code:
Form Build your own MVVM I have the following code that lets us have
Lets have the following code : ( function($) { TeacherModel = Backbone.Model.extend({ defaults :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.