ios - Show drop down menu when typing -


i have uitextfield , create bit drop down menu in ios contact app.

when user starts typing, menu drop down. doesn't need limit data shows based on names great if (ex: if user types "m" shows strings beginning m , on). if user selects one, type sent uitextfield displayed. if there open source picker this, great. if not, there way present that contains items array. not have complex, wouldn't have limit data shown when user types or anything.

response based on this link. show how url values in dropdown autocomplete.

  1. you need have nsmutablearray possible autocomplete values. in example, we’ll use nsmutablearray of pasturls, , every time user browses url we’ll add array.
  2. you need create uitable show values

     autocompletetableview = [[uitableview alloc] initwithframe:  cgrectmake(0, 80, 320, 120) style:uitableviewstyleplain];  autocompletetableview.delegate = self;  autocompletetableview.datasource = self;  autocompletetableview.scrollenabled = yes;  autocompletetableview.hidden = yes;    [self.view addsubview:autocompletetableview]; 
  3. you need show table when field being edited

    - (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string {       autocompletetableview.hidden = no;       nsstring *substring = [nsstring stringwithstring:textfield.text];      substring = [substring stringbyreplacingcharactersinrange:range withstring:string];      [self searchautocompleteentrieswithsubstring:substring];      return yes; } 
  4. and show stuff in table being edited

     -(void)searchautocompleteentrieswithsubstring:(nsstring *)substring {       // put starts substring autocompleteurls array       // items in array show in table view       [autocompleteurls removeallobjects];       for(nsstring *curstring in pasturls)  {           nsrange substringrange = [curstring rangeofstring:substring];           if (substringrange.location == 0) {                [autocompleteurls addobject:curstring];            }      }           [autocompletetableview reloaddata];   } 

don't forget add proper uitable , uitextfield delegates .h file.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -