【发布时间】:2020-06-07 17:45:44
【问题描述】:
我正在尝试实现一个按钮来触发我在 UItextView 中的原始文本。我看过这篇文章: Trigger button to change text in UITextView in swift3 xcode 8 ios 10
然后我意识到它只适用于 UItextField。由于我需要包装我的文本,我想知道是否可以使用 UItextView 执行类似的操作?
目前,我有:
@IBOutlet var Textfield: UITextView!
@IBOutlet var ChangingText: [UIButton]!
@IBAction func ChangingTextTapped(_ sender: Any) {
Textfield.text = "Changing text here"
}
但我收到以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM setText:]: unrecognized selector sent to instance 0x282d15b90'
提前致谢!
解决方案: 按照 Dejan Atanasov 的建议,它运行良好:
@IBOutlet var Textfield: UITextView!
@IBOutlet var ChangingText: UIButton!
@IBAction func ChangingTextTapped(_ btn: UIbutton) {
Textfield.text = "Changing text here"
}`
【问题讨论】: