Want to detect tab button pressed in ipad app from wireless keyboard
HI I want to detect tab button pressed in iPad app from wireless keyboard(external keyboard) So I make n开发者_运维问答ext textfield first responder. I am doing the following code, But it not working on tab key. It working fine incase return key.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if(textField == textName){
if ([string isEqualToString:@"\t"]) {
[textName resignFirstResponder];
[textRno becomeFirstResponder];
}
}
return YES;
}
Is there any other way for it.
Seems you want to switch to the next input view (e.g. text field) on tab stroke. The system does this automatically!
You can control the "tab-order" using the view tags and the code in this answer: https://stackoverflow.com/a/1351090/550177
Also look at these related questions:
- How do you set the tab order in iOS?
- How to navigate through textfields (Next / Done Buttons)
TextField delegate never get called for a tab button on the keyboard..
you can catch the \t
escape char when you pressed on your external keyboard:
- the alt
+ tabulator
or
- the ctrl
+ tabulator
.
to press the tabulator
button only does not cause any effect as you've already experienced because when the tabulator
button is pressed, your application won't get any feedback about this event, therefore you cannot handle when the user presses this button only.
This is how I switch to the next responder with the tab key:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (self.currentTextField != nil && self.currentTextField == textField)
[self switchToNextResponder];
self.currentTextField = textField;
return YES;
}
Might want to print the key received instead of checking for \t to make sure your keyboard handling routine works, and it will tell you what to look for also.
use a UIEvent approach at here
I'm surprised nobody else appears to have solved this on iOS.
I devised a solution that handles both Tab and Shift+Tab to go forward and backward to any field you want on iOS, and doesn't use any private APIs.
I wrote about it here: http://weaklyreferenced.wordpress.com/2012/11/13/responding-to-the-tab-and-shift-tab-keys-on-ios-5-ios-6-with-an-external-keyboard/
精彩评论