我在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