Ios 如何获得可自动调整大小的UITableView?
我在UIView中有几个并排的UITableView,我想让整个事情自动调整大小。我的init方法中有一个UIView,我正在执行:Ios 如何获得可自动调整大小的UITableView?,ios,uitableview,autoresize,autosize,Ios,Uitableview,Autoresize,Autosize,我在UIView中有几个并排的UITableView,我想让整个事情自动调整大小。我的init方法中有一个UIView,我正在执行: // I don't know how big frontBack should be, so I'd like it to autosize UIView *frontBack = [[UIView alloc] initWithFrame:CGRectZero]; frontBack.autoresizingMask = UIViewAutoresizingF
// I don't know how big frontBack should be, so I'd like it to autosize
UIView *frontBack = [[UIView alloc] initWithFrame:CGRectZero];
frontBack.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
UITableView *table = [[UITableView alloc]
initWithFrame:CGRectMake(0, 0, r.size.width / 2, height) style:UITableViewStyleGrouped];
table.autoresizingMask = UIViewAutoresizingFlexibleHeight;
table.dataSource = model1;
[table reloadData];
[frontBack addSubview:table];
... (add second table similarly, except with model2)
...
controller.view = frontBack;
这是行不通的。桌子是“高度”像素,比他们需要的要小;文本被删掉了
我尝试了几种方法来调整UITableView的大小,但运气不佳
// contentSize is correct, but frame size does not change
[table reloadData];
table.frame.size.height = table.contentSize.height;
// contentSize is correct, but bounds does not change
[table reloadData];
table.bounds.size.height = table.contentSize.height;
// Nothing appears to change
[table setNeedsLayout];
[table layoutIfNeeded];
// Again, no change
[table sizeToFit];
我想我遗漏了一些基本的东西,但如果有人能指出是什么,我将不胜感激
table.bounds.size.height=table.contentSize.height
这是只读属性,需要重新设置帧
另外,您确定包含的UIView没有切断表内容吗?您还应该调整它的大小。您想在UITableView中显示什么?TableView是滚动视图,如果需要,通常会滚动其内容?如果高度像素太小,为什么要将其设置为该值?何时要调整大小?配置后也可调用[table reloadData]table@Tobi:“高度”像素太小,但我不想计算实际的大小:我要知道表格的边距有多大,页眉有多高,等等。所有这些都是自动调整大小的目的!我也尝试过用上面给出的方法调整它的大小,但是由于UITableView没有正确调整大小,我想我不能期望UIView正常工作。没有办法只知道表的高度,你必须计算它。如果您使用的是6.0+,那么为什么不使用约束呢?