Hi all,
I am fighting with the focus engine and it's driving me crazy.. cannot figure it out although it looks pretty simple..
I have 2 text fields and 1 button stacked vertically. when the view controller loads the first text field is focused.
Clicking on that text field brings up a keyboard. On a keyboard clicking the Next button allows editing the second textfield and because it is the last textfield keyboard shows Done button. Clicking it closes keyboard and we're back to the controller, but there the focus is still on the first textfield.
I cannot focus the button after going through all the fields (using keyboard)...
I tried using the preferredFocusedView method but it does not work. It hits and it even returns the button but the button is never focused.
-(UIView *)preferredFocusedView {
if (doneCondition) {
doneCondition = NO;
return self.button;
} else {
return self.firstField;
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
if ([textField isEqual:self.secondField]) {
doneCondition = YES;
[self setNeedsFocusUpdate];
[self updateFocusIfNeeded];
}
}The closest I have got was using the didUpdateFocusInContext to change the focus, but in this case the change from the first textfield to the button is visible and it is ugly (you can see focus jumping from texfield to the button)...
Any ideas?
Thank you in advance!