iOS - UITextField 被 UILabel 压扁

发布于 2024-12-29 08:58:19 字数 702 浏览 6 评论 0原文

我有一个问题,IB 中显示的内容实际上并不是模拟器中显示的内容。请参阅以下屏幕截图:

在此处输入图像描述

正如您所看到的,它是一个简单的 UITableViewCell,包含一个标签和一个文本字段(灰色背景表明它在那里)。

这是它在模拟器中的显示方式:

在此处输入图像描述

如您所见,标签完全将文本字段压缩为细胞的末端。可能是什么原因造成的?我的代码如下:

[[(MyCustomCell *)cell textLabel] setText:[NSString stringWithFormat:@"email"]];

该单元只是使用 loadNibNamed:NSStringFromClass 创建的。我不会以编程方式向单元格添加任何其他字段。唯一的动态部分是实际的标签重命名。

欢迎任何想法,干杯!

更新:

当我选择该字段时,会发生这种情况:

在此处输入图像描述

或者,如果我长按该字段,则会出现放大镜出现,我可以看到文本字段中的文本。这确实很奇特。

I have an issue where what is being shown in IB is not actually what is appearing in the simulator. Please see the following screen captures:

enter image description here

As you can see it is a simple UITableViewCell, containing a label and a text field, (the grey background is demonstrate it being there).

This is how it appears in the simulator:

enter image description here

As you can see, the label is completely squashing the textfield to the end of the cell. What could be causing this? My code is as follows:

[[(MyCustomCell *)cell textLabel] setText:[NSString stringWithFormat:@"email"]];

The cell is just created using loadNibNamed:NSStringFromClass. I do not add any other fields to the cell programmatically. The only dynamic part is the actual label renaming.

Any ideas welcome, cheers!

UPDATE:

When I select the field, this occurs:

enter image description here

Or if I long press the field, a magnifying glass appears and I can see the text in the text field. This is really peculiar.

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

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

发布评论

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

评论(2

上课铃就是安魂曲 2025-01-05 08:58:19

我的猜测:标签和文本字段的自动调整大小设置不正确。在IB中检查它,您可以在其中设置元素的框架大小,超出的是自动调整大小。

My guess: the Autosizing was not set correct for both the Label and the Textfield. Check it in IB, where you set the frame size for an element, beyond is the autosizing.

还在原地等你 2025-01-05 08:58:19

刚刚意识到我的错误——真的很愚蠢!

我正在访问 iOS 属性 textLabel,而不是我的 IBOutlet textField。另一个自动完成错误!

Just realised my mistake - pretty stupid really!

I was accessing the iOS property textLabel, instead of my IBOutlet textField. Another autocomplete mistake!

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