ios UITextView setText 不更新文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6528565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:34:25  来源:igfitidea点击:

UITextView setText is not updating the text

iosios4interface-builderuitextview

提问by user605957

In my nib, I have a UITextViewcomponent.

在我的笔尖,我有一个UITextView组件。

In my code I have a UITextViewfield and I have used Interface Builder to make sure that the two are connected (at least I think I did that by dragging from "Files Owner" and dropping it on the UITextViewin Interface Builder and selecting my member variable).

在我的代码中,我有一个UITextView字段,并且我使用了 Interface Builder 来确保两者已连接(至少我认为我是通过从“文件所有者”中拖动并将其放在UITextViewInterface Builder 中并选择我的成员变量来做到这一点的) .

Now, when I update the text via setText, the UITextView still remains blank.

现在,当我通过 更新文本时setText, UITextView 仍然保持空白。

Thanks DeShawn

谢谢德肖恩

回答by Oras

Have you used

你用过吗

  @property(nonatomic,retain) UITextView *yourTextViewName;

then

然后

  @synthesize yourTextViewName;

in .mfile?

.m文件中?

If yes, use the following code in viewDidLoadafter updating the value to check:

如果是,则viewDidLoad在更新值后使用以下代码进行检查:

   NSLog(@"Text View Value = %@",yourTextViewName.text);

回答by erleyo

If it isn't figured it out yet; check out iOS Text View Not Updating

如果还没有弄清楚;查看iOS 文本视图未更新

The referencing yourTextViewName must be an IBOutlet UITextView *yourTextViewnameThen add the @property (nonatomic, retain) UITextView *yourTextViewName. Add the @synthesize yourTextViewNamein the corresponding .m file.

引用 yourTextViewName 必须是一个IBOutlet UITextView *yourTextViewname然后添加@property (nonatomic, retain) UITextView *yourTextViewName. @synthesize yourTextViewName在相应的 .m 文件中添加。

To set the text, use

要设置文本,请使用

yourTextViewName.text = @"some text";

回答by poetinthemirror

This may sound crazy, but I had to explicitly set the hidden property of UITextView to NO in code and then it started showing up. See if this works for you.

这听起来可能很疯狂,但我必须在代码中将 UITextView 的隐藏属性显式设置为 NO,然后它开始显示。看看这是否适合你。