简体   繁体   English

UITableViewController-TableView宽于屏幕

[英]UITableViewController - TableView wider than screen

I'm having some problem my whole day. 我整天都遇到一些问题。 I'm using UITableViewController. 我正在使用UITableViewController。 TableView has 5 static cells. TableView具有5个静态单元格。 I put a label inside my cell and gave it constraints. 我在单元格中放置了一个标签,并赋予了它约束。 This is my cell: 这是我的手机: 细胞

Every time when I change the screen to different version of iPhone, it gives me warning that width of this label is 600 (default in storyboard) and it goes of the screen on the right side. 每次将屏幕更改为其他版本的iPhone时,都会警告我该标签的宽度为600(情节提要中的默认值),并且它出现在屏幕的右侧。 Why TableViewController is not setting TableView screen size? 为什么TableViewController不设置TableView屏幕大小? What am I missing here? 我在这里想念什么? Is this actually a subview of viewController and if so, how to tell proper size of tableView inside storyboard with constraints? 这实际上是viewController的子视图吗?如果是,如何在带有约束的情节提要中分辨出tableView的正确大小?

Just place a table view controller into your storyboard and configure your static cells. 只需将表视图控制器放入情节提要中并配置静态单元格即可。 No constraints needed for this step. 此步骤不需要任何约束。 For your labels you need a different set of constraints: 对于标签,您需要一组不同的约束:

From your picture I'm assuming you want your label to be on the left side of your table view just like in most table view cells. 从您的图片中,我假设您希望标签像大多数表格视图单元格一样位于表格视图的左侧。 In that case you don't need to expand the width like that. 在这种情况下,您不需要像这样扩大宽度。 Just drag a label into your table view cell, place it on the left side, and a) center it vertically b) pin it to the right side of the screen as shown in the screenshot (ignore the value and make sure to uncheck constrain to margin. Hope this helps! 只需将标签拖动到表格视图单元格中,将其放在左侧,然后将其垂直居中b)将其固定在屏幕的右侧,如屏幕截图所示(忽略该值,并确保取消选中限制为保证金,希望对您有所帮助!

在此处输入图片说明

Yes, as cyril says, best option is to Use TableViewController in storyboard and set as 'static prototype'. 是的,正如西里尔所说,最好的选择是在情节提要中使用TableViewController并将其设置为“静态原型”。 Default is 'Dynamic'. 默认为“动态”。 Then you don't need to manage table view in the code. 然后,您无需在代码中管理表格视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM