Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (keyboard)
Viewing all articles
Browse latest Browse all 352

Displaying Keyboard Toolbar Icons as Part of Editable Webview in iOS Module

$
0
0

We have an iOS module with a single view in which a UIWebView is embedded as subview. This webview is editable and upon editing we want a keyboard toolbar displayed with RTF editing icons.

Here is a screenshot of the desired output.

In Xcode, the keyboard toolbar replacement is accomplished as follows (relevant Stackoverflow, confirmed that it works in an Xcode app). 1. finding the keyboard window and 2. iterating over the keyboard window's subviews and their subviews until we find the UIWebFormAccessory element and replacing it with UIToolbar.

1) finding the keyboard window

UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
    if (![[testWindow class] isEqual:[UIWindow class]]) {
        keyboardWindow = testWindow;
        break;
    }
}

2) iterating until we find UIWebFormAccessory and replacing it

for (UIView *formView in [keyboardWindow subviews]) { //<--this loop isn't entered when code is part of an Appcelerator module, but does work in Xcode standalone app
    for (UIView *subView in [formView subviews]) {
        if ([[subView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
            [subView.superview addSubview:our_custom_UIToolbar];
        }else if([[subView description] rangeOfString:@"UIImageView"].location != NSNotFound){
            [subView setFrame:CGRectZero];
        }
    }
}
However when module is called from Appcelerator, the keybaordWindow has no children, and therefore part 2 of the code (iterating over keyboard window's subviews) is never executed.

We are trying to understand why the keyboard window's tree structure changes depending on whether an Appcelerator or a native project is running and what we can do to get our custom UIToolbar installed successfully on the keyboard.

For the record, we have tried to do it with a TextField, as well, as the Objective-C code to mount a toolbar on the keyboard is a single line (theTextfield.inputAccessoryView=theToolbar). Same thing, works in Xcode app project, doesn’t work in Appcelerator app.


Viewing all articles
Browse latest Browse all 352


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>