6

Within my swift app, I am trying to hide the inputAccessoryView that shows when a user taps a textfield inside of a webview.

Here is the code attempting to do that:

  func keyboardWillShow(notification: NSNotification) {      
        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {        
            var keyboardView = UIApplication.sharedApplication().windows.last!.subviews.first!
            keyboardView.inputAccessoryView = nil           
        } 
    }

But I am getting this error:

Cannot assign to property: ‘inputAccessoryView’ is a get-only property

Is there a better way to do this? Any ideas on how to get this to work?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Lego Astronaut
  • 79
  • 1
  • 3
  • 8

1 Answers1

1

I think the error is due to the way the keyboardView is declared.

When I create my own UIView and assign it as the inputView for a first responder, I can then assign (or set to nil) the first responder's inputAccessoryView.

I assume you are trying to remove an existing accessory view, as Apple says that the default value is nil. I found this workaround for iOS 7, maybe this still works? Somebody subclassed a UIWebDocumentView and then put in an implementation of inputAccessoryView that returns nil. It's in Obj-C, but it looks promising:

iOS 7 UIWebView keyboard issue

Community
  • 1
  • 1