Programmatically change focus after entering text in UITextfield

I have a simple view that has two text images as well as a button. All controls are arranged vertically. I can navigate from one control to another using the remote control. However, I am trying to work with the following scenario:

  • The user launches the application (the focus is on the first text field).
  • The user enters a text field and uses a full-screen keyboard, then she clicks the "Next" button
  • The application displays a second text field (full-screen keyboard), enters text in a specific text, and clicks "Finish"
  • The application exits the full-screen keyboard and focuses the button

While step 1-3 works out of the box, changing the focus programmatically (4) does not work. Here is the code:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if(textField == self.textfieldB) {
        self.activeView = self.textfieldB;
        [self setNeedsFocusUpdate];
        [self updateFocusIfNeeded];
        return YES;
    } 
    return NO;
}

and in - (UIView *)preferredFocusedViewI return everything that is stored in self.activeView (yes, it will return an instance of the button). All methods are called expected, but the focus does not change. What am I doing wrong here?

Thanks in advance!

+4
source share
2 answers

According to this forum of developer forums, the behavior is deliberate:

, , UIKit , , , - . , , . .

. , , UIKit .

+3

, UIViewController restoreresFocusAfterTransition false

restoresFocusAfterTransition = false FocusEnvironments

0

Source: https://habr.com/ru/post/1625242/


All Articles