Skip to content

Instantly share code, notes, and snippets.

@Moligaloo
Created July 26, 2012 05:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Moligaloo/3180458 to your computer and use it in GitHub Desktop.
Save Moligaloo/3180458 to your computer and use it in GitHub Desktop.
Disable the return key of keyboard
-(void)disableReturnKey{
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIKeyboard.
UIView *foundKeyboard = nil;
for (UIView *possibleKeyboard in [keyboardWindow subviews]) {
// iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.
if ([[possibleKeyboard description] hasPrefix:@"<UIPeripheralHostView"]) {
possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0];
}
if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboard"]) {
foundKeyboard = possibleKeyboard;
break;
}
}
[foundKeyboard performSelector:@selector(setReturnKeyEnabled:) withObject:NO];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment