简体   繁体   中英

UITableViewController - TableView wider than screen

I'm having some problem my whole day. I'm using UITableViewController. TableView has 5 static cells. 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. Why TableViewController is not setting TableView screen size? 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?

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!

在此处输入图片说明

Yes, as cyril says, best option is to Use TableViewController in storyboard and set as 'static prototype'. Default is 'Dynamic'. Then you don't need to manage table view in the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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