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

1

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?

Teth answered 18/10, 2016 at 21:25 Comment(0)
D
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

Deva answered 19/10, 2016 at 0:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.