0

我通过隐藏默认键盘为 webview 使用自定义键盘。但是每当我点击输入框时,我的代码就会崩溃。它说

-[UITextInteractionAssistant containerIsTextField]: message sent to deallocated

经过大量调试,我发现 [self.view endEditing:YES]; 可用于 UITextInteractionAssistant。

有人可以帮忙吗?

提前帮忙!!!


// register for keyboard show event
[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(keyboardWillShow:)
 name:UIKeyboardWillShowNotification
 object:nil];

隐藏 UIWebviewAccessary

 -(void)keyboardWillShow:(NSNotification *)note {
    [self.view endEditing:YES];

    [self removeBar];
    [self performSelector:@selector(adjustFrame) withObject:nil afterDelay:0.03];
}

- (void)adjustFrame {
    [self.webView stringByEvaluatingJavaScriptFromString:@"window.scroll(0,0)"];
}

- (void)removeBar {
    // Locate non-UIWindow.
    UIWindow *keyboardWindow = nil;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        if (![[testWindow class] isEqual:[UIWindow class]]) {
            keyboardWindow = testWindow;
            break;
        }
    }

    // Locate UIWebFormView.
    for (UIView *possibleFormView in [keyboardWindow subviews]) {
        // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
        if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
            for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
                if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
                    [subviewWhichIsPossibleFormView removeFromSuperview];
                }
            }
        }
    }
}
4

0 回答 0