15

Another "how to remove the pre, next, done button" -question you may think. Not really actually. I've done some rather thorough research on this and tried out different approaches but no method or solution really seems to do it right. All workaround (that's what they are) mentioned and shown below are basically the same approach, replace content of the MainViewController.m file. I'm well aware of that more or less all these proposed solutions are somewhat hacky but still, there should be someone out there who has tackled this issue with a little bit of grace and deep thought, or someone who knows C well and can propose a more solid solution.

Allow me to illustrate my point by making references to some proposed solutions:

Solution 1

In iOS6, this results in the form assistant bar border still being present and the keyboard acting as if the form assistant bar were still there.

Solution 2

Someone proposed a solution to the above but I simply cannot get it to work. The answerer has made several edits and comments to the post which only make harder to grasp what to do where. I've tried all variations of his solution but I always end up getting a critical error and the project simply wont compile.

Solution 3

Not a C programmer (that's why I use phonegap) so can't get this to work properly. Don't know what to add where.

Solution 4

Don't know where and how to implement this so haven't tried it. Where should I register to receive the keyboardDidShow notification? Where should I add the function?

Conclusion

According to my research, if you will, no one has yet proposed a proper solution to this. So has anyone successfully removed the form assistant without any of the above mentioned side effects?

Community
  • 1
  • 1
Lindros
  • 253
  • 2
  • 12

6 Answers6

7

Here you go, I'm using this in an app I'm currently developing. Fingers crossed that it gets to the app store, although going on other 'hacks' that make it to the store this is no worse than others, so should stand a fair chance.

No annoying side effects with this method - it cleanly removes the bar by making sure it's never created in the first place. Ta da!

Credit goes to https://gist.github.com/2048571, this is his code with a small fix.

#import <objc/runtime.h>
#import <UIKit/UIKit.h>

@interface UIWebView (HackishAccessoryHiding)
@property (nonatomic, assign) BOOL hackishlyHidesInputAccessoryView;
@end

@implementation UIWebView (HackishAccessoryHiding)

static const char * const hackishFixClassName = "UIWebBrowserViewMinusAccessoryView";
static Class hackishFixClass = Nil;

- (UIView *)hackishlyFoundBrowserView {
    UIScrollView *scrollView = self.scrollView;

    UIView *browserView = nil;
    for (UIView *subview in scrollView.subviews) {
        if ([NSStringFromClass([subview class]) hasPrefix:@"UIWebBrowserView"]) {
            browserView = subview;
            break;
        }
    }
    return browserView;
}

- (id)methodReturningNil {
    return nil;
}

- (void)ensureHackishSubclassExistsOfBrowserViewClass:(Class)browserViewClass {
    if (!hackishFixClass) {
        Class newClass = objc_allocateClassPair(browserViewClass, hackishFixClassName, 0);
        IMP nilImp = [self methodForSelector:@selector(methodReturningNil)];
        class_addMethod(newClass, @selector(inputAccessoryView), nilImp, "@@:");
        objc_registerClassPair(newClass);

        hackishFixClass = newClass;
    }
}

- (BOOL) hackishlyHidesInputAccessoryView {
    UIView *browserView = [self hackishlyFoundBrowserView];
    return [browserView class] == hackishFixClass;
}

- (void) setHackishlyHidesInputAccessoryView:(BOOL)value {
    UIView *browserView = [self hackishlyFoundBrowserView];
    if (browserView == nil) {
        return;
    }
    [self ensureHackishSubclassExistsOfBrowserViewClass:[browserView class]];

    if (value) {
        object_setClass(browserView, hackishFixClass);
    }
    else {
        Class normalClass = objc_getClass("UIWebBrowserView");
        object_setClass(browserView, normalClass);
    }
    [browserView reloadInputViews];
}

@end
Jordan Smith
  • 10,310
  • 7
  • 68
  • 114
  • I initially thought nicaou was it but it turned out to be rather buggy. So far, your solution is the only one that actually does work perfectly. I wish one could be able to show/hide this bar dynamically but as it's not even being created in the first place, I'm guessing it's more or less impossible. You should add this to your answer though: Don't forget to call this method from ViewDidLoad or similar via `self.view.frame = [[UIScreen mainScreen] applicationFrame];` – Lindros Feb 08 '13 at 20:39
  • Looks great. Doesn't flicker, removes the grey line, clever solution too. – Robert Karl May 21 '13 at 21:12
  • Could you please tell me how to import this framework? – Aswin Sathyan Feb 08 '16 at 12:23
7

For anyone still struggling with this, Phonegap now has two properties for disabling the form accessory bar issue and the problem of page scrolling when input and text area fields trigger the keyboard.

Just set the following in your config.xml and your good to go.

<preference name="HideKeyboardFormAccessoryBar" value="true" />
<preference name="KeyboardShrinksView" value="true" />

Link to Phonegap Documentation

PassKit
  • 12,231
  • 5
  • 57
  • 75
  • Just started to got struggling, and then you posted this. Thanks! – idmean Sep 07 '13 at 07:46
  • 2
    The HideKeyboardFormAccessoryBar option is not present in the docs for newer versions of Phonegap (3.1, 3.2 and 3.3) - anyone know what happened? Update: it's ok - it was just moved from the iOS docs to the general config.xml docs: http://docs.phonegap.com/en/3.3.0/config_ref_index.md.html – jackocnr Feb 18 '14 at 21:36
2

There is no public (so, App Store-allowed) way to disable the form assistant bar on web views for UIWebView (which AFAIK is what PhoneGap uses) form elements in any version of iOS.

millenomi
  • 6,569
  • 4
  • 31
  • 34
  • We know, but perhaps a better hack that does it better than the above mentioned examples? Those examples tell you it can be done and I'm using it in my app so that kind of solution is allowed. Having concluded that it can be done (using some hack) and that those methods are allowed, there should be someone who has worked out a way to do it **right** – Lindros Jan 15 '13 at 19:08
2

This looks like the cordova plugin we have all been waiting for... https://github.com/don/KeyboardToolbarRemover

This allows a simple toolbar.hide() and toolbar.show()

Mulhoon
  • 1,852
  • 21
  • 26
  • I think you've hit the nail on the head with this one. I wish I had of known about this plugin a while ago. – gotnull Jan 23 '13 at 23:22
  • This is good, very good if only it the form assistant bar were removed prior to that of it being deployed so that the view doesn't "shake" every time the keyboard pops up. Otherwise a very nice suggestion. Thank you – Lindros Feb 08 '13 at 20:37
2

If you are using phonegap/cordova 3 CLI, you now require a plugin to remove the toolbar. Install it via the terminal..

$ cordova plugin add org.apache.cordova.keyboard 

and use this in your javascript

Keyboard.hideFormAccessoryBar(true);

But... it's not perfect. Firstly if you intend to use input.focus() to bring up the keyboard, then the toolbar is shown briefly before being hidden. From then on it's fine. If you allow a user to click directly in the input field it will be fine.

Then there can be movement at the top of the screen, which can be solved with this answer.. How to fix keyboard issues with Cordova 3.1 on iOS?

It can be difficult to get right, so I'd ask yourself if you really need to hide it, or can you make it useful for the user instead?

Community
  • 1
  • 1
Mulhoon
  • 1,852
  • 21
  • 26
1

This worked for me: https://github.com/don/KeyboardToolbarRemover

You will have to know though, there is no Cordova.plist file as of Phonegap 2.3.0 - instead edit your config XML file with the following:

<plugin name="KeyboardToolbarRemover" value="KeyboardToolbarRemover" />

in the branch

mr.subtle
  • 65
  • 1
  • 7