简体   繁体   English

快速在键盘上方添加视图,但出现错误无法分配给属性:“ inputAccessoryView”是仅获取属性

[英]Swift adding view above keyboard getting Error Cannot assign to property: 'inputAccessoryView' is a get-only property

My scenario, I am trying to add UIView on top of the keyboard for toolbar. 我的情况是,我试图将UIView添加到工具栏的键盘上方。 here, I am using below code for growing textview 在这里,我使用下面的代码来增加textview

https://github.com/muukii/NextGrowingTextView https://github.com/muukii/NextGrowingTextView

I added additionally UIView in Viewcontroller top side and added below code into Viewcontroller 我在Viewcontroller顶部另外添加了UIView,并在Viewcontroller中添加了以下代码

@IBOutlet var toolBarView: UIView!
@IBOutlet weak var growingTextView: NextGrowingTextView!

in ViewDidLoad() added below line 在ViewDidLoad()中添加以下行

self.growingTextView.inputAccessoryView = toolBarView

I am getting below error, how to fix this? 我遇到错误,该如何解决?

Cannot assign to property: 'inputAccessoryView' is a get-only property 无法分配给属性:“ inputAccessoryView”是一个只读属性

If I add below line 如果我在下面添加

self.growingTextView.textView.inputAccessoryView = toolBarView

I am getting output like below screen in iPhone X series (Other devices working fine). 我在iPhone X系列中的屏幕下方得到了类似的输出(其他设备运行正常)。

current output getting gap between toolbarview and growingTextView 当前的输出越来越工具栏视图和growthTextView之间的差距

To answer your question: The error occurs because class NextGrowingTextView is of type UIScrollView and you simply cannot change a scroll view's inputAccessoryView . 回答您的问题:发生错误是因为类NextGrowingTextView的类型为UIScrollView而您根本无法更改滚动视图的inputAccessoryView You can see that in NextGrowingTextView.swift. 您可以在NextGrowingTextView.swift中看到它。

You should - though - be able to modify self.growingTextView.textView.inputAccessoryView . 但是,您应该能够修改self.growingTextView.textView.inputAccessoryView

You've to use 你必须使用

self.growingTextView.textView.inputAccessoryView = toolBarView

instead of 代替

self.growingTextView.inputAccessoryView = toolBarView

Because growingTextView is a object instance of NextGrowingTextView which is subClass of UIScrollView and in this for textView used NextGrowingInternalTextView . 因为growingTextView是的对象实例 NextGrowingTextView这是子类UIScrollView并且在该对textView使用NextGrowingInternalTextView

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

相关问题 无法分配给属性:'inputAccessoryView'是一个get-only属性 - Cannot assign to property: ‘inputAccessoryView’ is a get-only property 无法分配给属性:“ size”是仅获取属性Swift - Cannot assign to property: 'size' is a get-only property Swift Swift无法通过下标分配:“ peerDeviceSettings”是仅获取属性” - Swift Cannot assign through subscript: 'peerDeviceSettings' is a get-only property" 无法分配给属性:“值”是一个只能获取的属性 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 我该如何解决这个问题“无法分配给属性:'typ' 是一个只能获取的属性” - How can I solve this problem “Cannot assign to property: 'typ' is a get-only property”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM