自动调整大小的单元格xib到tableview单元格宽度和行高 [英] Autoresize cell xib to tableview cell width and row height

查看:89
本文介绍了自动调整大小的单元格xib到tableview单元格宽度和行高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用自定义tableviewcell xib,希望它的大小自动调整为tableview的宽度和行的高度.

I am currently working with a custom tableviewcell xib and want the size of it to be automatically resized to the tableview's width and it's row's height.

单元格视图的大小不会自动调整为表格视图.因此,我尝试更改 tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath)委托中的框架,但未反映任何更改(如果我在实际上改变之前和之后打印框架大小).

The size of the cell's view does not auto adjusts to the tableview. So I have tried to change the frame inside the tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) delegate no changes are reflected (if I print the frame size before and after it does in fact change.)

有人知道解决方案吗?最好的情况是使单元格的框架自动调整为表格视图的宽度和行高.

Does anyone know a solution for this? The best case would be to make the cell's frame auto adjust to the tableview's width and row height.

进一步检查后,问题可能与iOS8 Size类有关.当我调整xib内部的单元格大小时,它只会扩展到比表格视图大小更大的宽度.该标签应该位于中间(已将它们设置为约束并以编程方式获得了相同的结果).

After further examination the problem probably has to do with iOS8 Size classes. When I resize the cell inside the xib, it will just expand to a greater width than the table view's size. The label is supposed to be in the center (had set them with constraints and programmatically, got the same results).

以下是屏幕截图:

推荐答案

发现了问题,这是我的错误.我从未在ViewController内对TableView设置约束,因此它保持了iOS 8中引入的Size Classs定义的默认基本大小.

Found the problem, and it was my mistake. I never set constraints to the TableView inside the ViewController, so it maintained the default base size defined by Size Classes introduced in iOS 8.

这就是为什么单元格的宽度扩展为视图控制器宽度的两倍的原因.

That is why the width of the cell expanded about the double of the view controller's width.

这篇关于自动调整大小的单元格xib到tableview单元格宽度和行高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆