-1

I'm trying to make a country and state textfield auto-complete and I have all records the in JSON from a server database, but I don't know how to call the JSON inside Xcode and assign to the autocomplete textfield.

How can I consult this data when the user is typing?

Joe Masilotti
  • 16,815
  • 6
  • 77
  • 87
  • 3
    Welcome to Stack Overflow! Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! Also see [ask]. – emartinelli Mar 16 '16 at 12:03

1 Answers1

0

Its a long process,

Go step by step:

  1. Fetch all data from your server
  2. Parse those data in your understanding form (NSArray or NSDictionary or whatever you like.)
  3. If you're using a simple UITextField then you should get notify if user is typing inside it. You can get this inside its delegate. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {...}
  4. You may require to use a NSPredicate to filter data from the array (Generated in step-2). You may require to use a like format with it. Using NSPredicate to filter an NSArray based on NSDictionary keys
  5. You will also require to have some flag isSearching (or something you prefer), set it to YES if you found that data.
  6. Reload your table.
  7. If you're good to code then you will have some data which looks like autocomplete.
  8. If not succeed then, check each steps in detail and find your problem.

At last, you can take reference from this site as well, good to start. Good luck.

Community
  • 1
  • 1
Hemang
  • 26,840
  • 19
  • 119
  • 186