title: AutoComplete for UITextfield in iOS
body: <p>I am working on new iOS application. In that app, I have 5 UITextFields and those are
  1. first interest, second interest upto 5 interests.</p>
  
  <p>I need to add Autocomplete for those 5 UITextFields. I have searched google for one day. I got some forums and tutorial for that. But I even have tried with Github links also. </p>
  
  <p>According to my requirement, I have an array of data which is getting from my server. In that array, I have data like, coffee, cricket, etc. That is Autocomplete data. I need to display that array whenever user entered text in UITextField, if its related to my array of data, need to display below of that UITextFields.</p>
  
  <p>For that purpose i used following code.</p>
  
  <p>**// String in Search textfield</p>
  
  <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  
  NSString *substring = [NSString stringWithString:textField.text];
      substring = [substring stringByReplacingCharactersInRange:range withString:string];
      [self searchAutocompleteEntriesWithSubstring:substring];
      return YES;
  }
  </code></pre>
  
  <p>**</p>
  
  <p>// Take string from Search Textfield and compare it with autocomplete array</p>
  
  <pre><code>- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {
  
  // Put anything that starts with this substring into the autoCompleteArray
  // The items in this array is what will show up in the table view
  
  [autoCompleteArray removeAllObjects];
  NSLog(@"autoCompleteArray %@",autoCompleteArray);
  for(NSString *curString in elementArray) {
      NSRange substringRangeLowerCase = [curString rangeOfString:[substring lowercaseString]];
      NSRange substringRangeUpperCase = [curString rangeOfString:[substring uppercaseString]];
  
      if (substringRangeLowerCase.length != 0 || substringRangeUpperCase.length != 0) {
          [autoCompleteArray addObject:curString];
      }
  }
  
  autoCompleteTableView.hidden = NO;
  [autoCompleteTableView reloadData];
        }
  </code></pre>
  
  <p>And I created UITableView as <code>AutocompleteTableview</code> in <code>ViewDidLoad</code> method.</p>
  
  <p>**Issue is, if I type text as suppose "c", from my array of data displaying whatever text contains as "c" letter in tableview. But, if i typed "coff" no data displaying in that UITableView. Also how to validate which UITextField user clicking in <code>tableviewdidselectrowatindexpath</code> delegate method. I tried with assigning tag for those UITextFields, but its working in UITextFields delegate methods only, not in other place. so, whenever i selected data from UITableView, first UITextField only taking data not other UITextField. </p>
  
  <p>Please give your valuable suggestion, which is the best way to display the autocomplete for <code>UITextfields</code> in iOS for multiple UITextfields and how to handle UITableView for displaying data. If anything mistakes in my content forgive me and please provide your valuable suggestions to fix this issue.</p>
  
  <p>Thanks****</p>