Confirm AutoFill UITextview

This seems impossible, but maybe someone had the same problem.

Is it possible that I automatically use autocomplete or somehow get the suggested word? My problem is that I capture the press of the return / return key and then translates the focus to another text box. When you enter / reverse hit, the text image ignores the automatically suggested word. It seems like you can accept autocomplete with a space / dot (and return for a new line). With this code:

- (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { NSRange textViewRange = [textView selectedRange]; // Handle newrow and backspace. if(([text length] == 0) && (textViewRange.location== 0) && textViewRange.length==0){ // BACKSPACE KEYSTROKE [delegate doSomethingWhenBackspace]; return NO; }else if ([text isEqualToString:@"\n"]){ // RETURN KEYSTROKE [delegate doSomethingWhenReturn]; return NO; } return YES; } 

I tried to programmatically add a “space” when the return key is pressed, but also ignores the auto-complete word.

 else if ([text isEqualToString:@"\n"]){ // Tryin to accept autocomplete with no result. textview.text = [textview.text stringByAppendingString:@" "]; // RETURN KEYSTROKE [delegate doSomethingWhenReturn]; return NO; } 

Any suggestions?

+7
source share
4 answers

I had a very similar problem, I made an application that was supposed to read every letter in a text view, and I have problems when autocomplete is inserted into words because it saved it as if it were a single letter. you can add each character to an array and then check if there is more than one line in length. Or you can add each character that is placed in an array, and then run something like

 NSString *string = text; NSMutableArray *array = [NSMutableArray new]; for (int i=0; i<string.length; i++) { [array addObject:[string substringWithRange:NSMakeRange(i, 1)]]; } 

to add each character individually by comparing two arrays, you can determine whether auto-correction was used and with which word / s. Hope this helps.

-3
source

Call -resignFirstResponder (ie [textView resignFirstResponder] ) in the text field or text field that should accept autocomplete results: UIKit will change the .text property to include autocorrect text.

If you want to keep the keyboard after your first view resigns from the first responder, pass the responsibility of firstResponder to the next textual input view using [anotherTextView becomeFirstResponder] .

+4
source

For the reciprocal space and the space u, we can use this condition

 if ([[text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) { [delegate doSomethingWhenBackspace]; return NO; } 
0
source

I hope this link may be useful for you.

How to autocomplete with custom values

-one
source

All Articles