简体   繁体   English

无法分配给属性:'inputAccessoryView'是一个get-only属性

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

Within my swift app, I am trying to hide the inputAccessoryView that shows when a user taps a textfield inside of a webview. 在我的swift应用程序中,我试图隐藏inputAccessoryView,该视图显示用户点击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? 有关如何使其工作的任何想法?

I think the error is due to the way the keyboardView is declared. 我认为错误是由于keyboardView的声明方式。

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. 当我创建自己的UIView并将其指定为第一响应者的inputView时,我可以将第一个响应者的inputAccessoryView分配(或设置为nil)。

I assume you are trying to remove an existing accessory view, as Apple says that the default value is nil. 我假设您正在尝试删除现有的附件视图,因为Apple说默认值为nil。 I found this workaround for iOS 7, maybe this still works? 我找到了适用于iOS 7的解决方法,也许这仍然有效? Somebody subclassed a UIWebDocumentView and then put in an implementation of inputAccessoryView that returns nil. 有人将UIWebDocumentView子类化,然后放入一个返回nil的inputAccessoryView实现。 It's in Obj-C, but it looks promising: 它在Obj-C中,但看起来很有希望:

iOS 7 UIWebView keyboard issue iOS 7 UIWebView键盘问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 快速在键盘上方添加视图,但出现错误无法分配给属性:“ inputAccessoryView”是仅获取属性 - Swift adding view above keyboard getting Error Cannot assign to property: 'inputAccessoryView' is a get-only property 无法分配给属性:“ size”是仅获取属性Swift - Cannot assign to property: 'size' is a get-only property Swift 无法分配给属性:“值”是一个只能获取的属性 RxSwift - - Cannot assign to property: 'value' is a get-only property RxSwift - 无法分配给属性“tabBarController”是一个只能获取的属性 - Cannot assign to property 'tabBarController' is a get-only property 无法分配给属性:“ b0”是只读属性 - Cannot assign to property: 'b0' is a get-only property 无法分配给属性:“popupHeight”是一个只能获取的属性 - Cannot assign to property: 'popupHeight' is a get-only property 无法分配给属性:“输出”是仅获取属性 - Cannot assign to property: 'outputs' is a get-only property 无法分配给属性'observationTime'是一个get-only属性 - Cannot assign to property 'observationTime' is a get-only property Swift无法通过下标分配:“ peerDeviceSettings”是仅获取属性” - Swift Cannot assign through subscript: 'peerDeviceSettings' is a get-only property" 我该如何解决这个问题“无法分配给属性:'typ' 是一个只能获取的属性” - How can I solve this problem “Cannot assign to property: 'typ' is a get-only property”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM