在运行时更改 UITextView 中的文本

发布于 2024-09-13 23:09:40 字数 203 浏览 2 评论 0原文

我有一个仅包含文本视图的 ViewController。在其 viewDidLoad 方法中,我只需初始化 textView 并将其添加为子视图。在我的主 ViewController 类中,当用户按下按钮时,我会切换视图并显示具有 textView 的视图。我正在尝试更改 textView 的文本,但它不起作用。我不能在运行时更改 UITextView 的文本吗?

谢谢。

I have a ViewController consisting of just a textView. In its viewDidLoad method, I simply initialize the textView and add it as a subview. In my main ViewController class, when the user presses a button, I switch views and display the view that has the textView. I am trying to change the textView's text however it is not working. Can I not change the text of a UITextView at runtime?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美不过初阳 2024-09-20 23:09:40

您应该保留对文本视图的引用。

如果这样做,请在设置新文本之前确保引用正确且有效。

一般来说,当您发布有问题的代码时,它总是有帮助的 - 这样我们就可以更轻松地帮助您......

You should keep a reference to your text view.

If you do, then make sure that the reference is correct and valid before setting the new text.

In general, it always helps when you post a problematic code - this way it is much easier for us to help you...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文