我在UIView中有几个并排的UITableViews,我想让整个事情自动化。我有一个UIView在我的init()方法中:如何获得一个UITableView自动调整大小?
// 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;
这是行不通的。这些表格是“高度”像素高(比他们需要的小;文本被切断)。
我试图得到UITableViews调整大小的几种方法,没有运气
// 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];
我以为我失去了一些东西基本在这里,但我会很感激,如果有人能指出它是什么。
你想在'UITableViews'中显示什么? TableViews是滚动视图,通常在需要时滚动它们的内容? – Tobi 2013-04-07 17:00:10
另外,如果“高度”像素太小,为什么要设置它? – Tobi 2013-04-07 17:01:31
你想什么时候调整大小? – ipinak 2013-04-07 21:59:08