Text view listing suggestions in iOS

I am trying to implement a textView in which when the user begins to enter text (let them say names), he will display sentences, and when they click on them, he is added to the textView, than the user presses a comma and again the same functionality for another name .. ..

And at the end, the text in the textView should look like this:

Aron, Maria, Alex, Cassie

Can anyone suggest me how I can achieve this? (Its somewhat similar to adding β€œTags” when posting this question !!!)

Thanks.

+7
source share
5 answers

You can use the NSTokenField replacement, there are several libraries here:

tokenField libraries

+2
source

The following link may help you: http://www.raywenderlich.com/336/how-to-auto-complete-with-custom-values

Follow the same stream. To get the autocomplete suggestions after the decimal point, change the delegate method as shown below.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { autocompleteTableView.hidden = NO; NSString *names = [NSString stringWithString:textField.text]; NSArray* arr = [names componentsSeparatedByString:@","]; NSString *subString = [arr lastObject]; substring = [substring stringByReplacingCharactersInRange:range withString:string]; [self searchAutocompleteEntriesWithSubstring:substring]; return YES; } 

Provide an NSMutableArray named "allNames" that contains all the names you want to display in the list of sentences, and use it like the following:

 - (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring { [autocompleteUrls removeAllObjects]; for(NSString *curString in allNames) { NSRange substringRange = [curString rangeOfString:substring]; if (substringRange.location == 0) { [autocompleteUrls addObject:curString]; } } [autocompleteTableView reloadData]; } 

When the user clicks on the prompts, displays the name, adding with the previously entered names.

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // set the textField.text by appending this name to already entered names } 
+1
source

I have not seen anything like this in a mobile application. You can search libraries. But if you want to do it yourself, I would advise you to use an invisible tableView. When the user begins to enter a name, you should fetchData and show in tableView in text mode. It's not hard.

0
source

In a relatively simple way, I can think of, in order to achieve this functionality, it would add the appearance of a keyboard input that will offer suggestions.

You would not have to intervene in TextField yourself, and you would not need to include sentences in the rest of your application.

An auxiliary view can, for example, get a link to a text field and listen for input:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged) name:UITextFieldTextDidChangeNotification object:textFieldWithSuggestions]; 

It will contain a method - (void) textChanged; in which you will have the opportunity to split the existing text into components, using a comma or any other character as a separator, and then use the last piece of text to perform a search for possible completions.

He can represent these sentences as a series of buttons, for example (perhaps even in side-scrolling scrolling to allow for a lot of sentences), and if someone is pushing, update the text of the text fields, replacing the last text segment with a filled line.

To track which button indicates which sentence, simply indicate the tags according to the index of the search results. Thus, you only need one method as the target for the buttons.

0
source

If you need some kind of library code, you can go for this https://github.com/hoteltonight/HTAutocompleteTextField to help you

-one
source

All Articles