iOS - UITextField 被 UILabel 压扁
我有一个问题,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:
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:
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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的猜测:标签和文本字段的自动调整大小设置不正确。在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.
刚刚意识到我的错误——真的很愚蠢!
我正在访问 iOS 属性
textLabel
,而不是我的IBOutlet textField
。另一个自动完成错误!Just realised my mistake - pretty stupid really!
I was accessing the iOS property
textLabel
, instead of myIBOutlet textField
. Another autocomplete mistake!