1

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 = 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;

これは動作しません。テーブルの高さは 'height' ピクセルです (これは必要なサイズよりも小さく、テキストは切り取られています)。

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];

ここで何か基本的なことが欠けていると思いますが、誰かがそれが何であるかを指摘できればありがたいです.

4

1 に答える 1

0

table.bounds.size.height = table.contentSize.height;

これは読み取り専用のプロパティです。フレームを再度設定する必要があります。

また、含まれている UIView がテーブルのコンテンツを切り取っていませんか? サイズも変更する必要があります。

于 2013-04-08T01:29:52.487 に答える