prevent UIWebView inputs from displaying UIKeyboard without disabling user interaction - iphone

I have a UIWebView that loads and external product configuration web service UI that is basically a bunch of dependent Drop Down lists.
The problem is the Drop Downs are basically enhanced text input's so when the user taps them to display the options the UIKeyboard keeps popping up and own after they make their selection. it is less than a fluid process. Is there anyway to suppress the html inputs from triggering the UIKeyboard?

Then try this:
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(removeKeyBoard:) name:UIKeyboardDidShowNotification object:nil];
...
- (void)removeKeyBoard:(NSNotification *)notify {
// web is your UIWebView
[web stringByEvaluatingJavaScriptFromString:#"document.activeElement.blur()"];
}
remember to remove the notification and can filter it if only for your WebView object.

Try using the following code in the HTML:
<input type='text' width='100' onclick='blur()'>
with the method blur () and then you lose the focus will not appear on the keyboard.

Related

Keyboard hides as dialog dissappears

In my application i am using sharekit inorder to post on Facebook.On main screen i have a textview and a custom keyboard. When i click on Facebook button it will check about the user authentication tokens if present post will be published on Facebook if not it will display a dialog box to get username and password by user. When i click cancel button on that dialog the keyboard automatically hides.
My problems is I dont want keyboard to get hide. I had also used observer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardDidShowNotification
object:nil];
This observer will show keyboard.
The observer always called method keyboardWillShow but in case of dialog it wont. And my keyboard automatically hides when I cancel the dialog.And I am using iOS6 in iOS5 the same observer is working fine.
In that cancel method write code like below
[yourview endEditing:NO];
let me know is it working or not....
Happy Coding!!!!!!

How to get event or notification of the input method changing?(IOS5.1)

(In IOS 5.1 Xcode 4.3)
When the user clicked the button to switch keyboard input method, how to get to this event and to determine the state of the input method?
When the input method changes, although the keyboard is already there, iOS will send the UIKeyboardDidShowNotification. You can register yourself for this notification like:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
Thats actually all you can do from my point of view!
I'm not sure if it's possible to detect the current input method of the keyboard directly!
Or maybte take a look at the following discussion: Detecting current iPhone input language!

Default Keyboard appears in iPhone instead of my custom keyboard

I am making a custom keyboard in my app for iPhone. But when I tap on the UITextField the default keyboard also appears. Where as I want only my keyboard to pop-up on the screen. How do I stop default keyboard from appearing on the screen?
You can try the following line of code
your_TextField.inputView = your_CustomKeyboard;
I am not confirm that it will work for your custom Keyboard i tried this to use a datepicker as inputview and it did worked so it may help you
I got the answer to my question. Since I am new here i cudnt post an answer b4 8 hrs after my own question post. And yes Tejeshwar Gill, Thanks for the response and my solution matches your approach. Thanks again.
I used the NSNotificationCenter to notify me when the keyboard appears. I had used this method to resize my tableview when the keyboard appears, but that was quite some time before. So it didnt click me instantly then.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(hideKeyboard:)
name:UIKeyboardWillShowNotification
object:nil];
You need to hide the default keyboard inorder to show your custom keyboard. So use this:-
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil]; and in the method keyboardDidHide: , add [keyboard resignFirstResponder].

Customise Keybord and autocorrection type for UIWebview

I am using UIWebview in my app as richtexteditor, but when i am trying to return the keyboard by hitting 'Return' key on key board,it is working as enter button and control comes to next line
i am using this code,
- (void)viewDidLoad
{
[webView stringByEvaluatingJavaScriptFromString:#"document.activeElement.blur()"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
and how to Disable autocorect for the same, i want to use the code
<input type=\"text\" size=\"30\" autocorrect=\"off\" autocapitalization=\"off
and where and how should i write this code?
Code like <input type="text" size="30" autocorrect="off" autocapitalization="on"> has to go in the actual HTML that is being shown in the UIWebview.
As for how to make the keyboard go away when the user presses return, that'll depend on how your app is set up.
If you want to actually make the WebView submit the form by HTTP, then you want to add some JavaScript to your textarea:
<textarea onkeydown="if (event.keyCode == 13) { this.form.submit(); return false; }"></textarea>
Otherwise, there's no way to listen to the return key on the keyboard, so instead you'll have to add a different button for the user to press instead. If you want to add that to the accessory view of the keyboard—well, you can't, but here's a question on making it look like your new button is part of the keyboard accessory view:
iPhone - Adding a button to keyboard existing accessory view (keyboard from UIWebView)

Remove form assistant from keyboard in iPhone standalone web app

Is it possible to remove the form assistant from the iPhone popup keyboard in a standalone web app? I know the general consensus is that it's not possible in Mobile Safari, but a standalone app runs in a UIWebView, and functions differently in several ways (example), so I'm hoping this might be possible.
You can see it here right above the keyboard:
The Previous and Next buttons cycle between <form> inputs. But I have a single <input> element, so they are disabled. The Done button hides the keyboard, but since I have a height-flexible <ul> (that takes up the space between the keyboard and the <input>), and I have nothing else on this page, it serves no purpose.
On a tiny screen, and with almost half the screen taken up by the keyboard, the 44 pixels that make up this toolbar are a huge waste of space (an entire <li>'s worth).
Native iOS apps can remove it, so I know it's at least possible on the phone, I've just not discovered a way to do it in a web app. This is from the Facebook app and the page is very similar to mine:
I've tried using an <input> not wrapped in a <form> and also using a contenteditable <div>, but the results were the same. There are several custom -webkit- styles to control various aspects of the web app interface, but they are poorly documented, and a search turned up nothing on this.
Any way to remove the form assistant in a web app?
If you app is a web app wrapped in a native Objetive-C app this is possible by manipulating Keyboard views.
first, register to receive the keyboardDidShow notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
this will call the following method when keyboard shows up:
-(void)keyboardDidShow:(NSNotification*)notif
{
NSArray *array = [[UIApplication sharedApplication] windows];
for (UIWindow* wind in array) {
for (UIView* currView in wind.subviews) {
if ([[currView description] hasPrefix:#"<UIPeripheralHostView"]) {
for (UIView* perView in currView.subviews) {
if ([[perView description] hasPrefix:#"<UIWebFormAccessory"]) {
[perView setHidden:YES];
}
}
}
}
}
}
this method goes over the views on screen looking for the form assistant and hiding it.
NOTE: Apple probably won't reject this, as i've seen it being used by Facebook etc, but this technique might break in upcoming iOS releases.
All signs point to this not being possible, including several questions here.
You can do a category of UIView and "override" the behaviour of addSubview: like the example below. Call the method "exachangeMethods" from your applicationDidFinishLaunching of your AppDelegate.
#import "UIView+util.h"
#import <objc/runtime.h>
#implementation UIView (util)
// Swaps our custom implementation with the default one
// +load is called when a class is loaded into the system
+ (void) exchangeMethods
{
SEL origSel = #selector(addSubview:);
SEL newSel = #selector(customAddSubview:);
Class viewClass = [UIView class];
Method origMethod = class_getInstanceMethod(viewClass, origSel);
Method newMethod = class_getInstanceMethod(viewClass, newSel);
method_exchangeImplementations(origMethod, newMethod);
}
- (void) customAddSubview:(UIView *)view{
if( [[view description]rangeOfString:#"<UIWebFormAccessory"].location!=NSNotFound) {
return;
}
// This line at runtime does not go into an infinite loop
// because it will call the real method instead of ours.
return [self customAddSubview:view];
}
#end