[英]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.