Is there an iPhone equivalent for the NSResponder
methods -selectNextKeyView
or -nextValidKeyView
from Mac OS X? I know about the -becomeFirstResponder
method, but finding out which view to call that on is not very pretty when view hierarchies get more complicated.
There must be some kind of way to find this out as when I press tab when in the iPhone Simulator, focus does properly go to the next UITextField
. This made me wonder what exactly happens when I press tab. Any ideas?
Update: This does exactly what I want, but _nextKeyResponder
is private API, so a no-no. Is there any way to do a 'fake' tab key press without using private API?
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
// Try to find next responder
UIView *nextResponder = (UIView *)[self.view _nextKeyResponder];
if (nextResponder) {
// Found next responder, so set it.
[nextResponder becomeFirstResponder];
[self.tableView scrollRectToVisible:[self.tableView convertRect:[nextResponder frame] fromView:nextResponder] animated:YES];
} else {
// Not found, so remove keyboard.
[textField resignFirstResponder];
}
return NO; // We do not want UITextField to insert line-breaks.
}
Focus is an iPhone feature that lets you block all notifications except from specific people or apps. Introduced in iOS 15, Focus is like an advanced version of Do Not Disturb. Some Focus options also let you automatically reply with a prewritten message to anyone who texts you.
When you're finished using a Focus, you can quickly turn it off to allow notifications again. After you turn off a Focus, it still appears in Control Center and can be reused. Do any of the following: Touch and hold the Focus icon on the Lock Screen.
There is not a public iOS equivalent for NSResponder
's -selectKeyView
or -nextValidKeyView
.
When the first responder is an instance of UITextField
, pressing tab instantiates a private subclass of UIEvent
which is passed to -[UIApplication sendEvent:]
, which in turn calls -[UIView _nextKeyResponder]
.
-[UIView _nextKeyResponder]
doesn't work quite the way you think it does. It treats the key view chain as a loop, so your else
block will never be reached. For the same reason, even if there was a public API for synthesizing keyboard events, you probably wouldn't want to use it.
Instead, you probably want something more like UIWebView
's UIToolbar
-based form input accessory. Its buttons can be enabled and disabled when appropriate, and its delegate handles the actual button press actions.
To implement such a delegate in a general way, however, it might be helpful to look at how -[UIView _nextKeyResponder]
is implemented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With