3

テーブルビューを含むViewControllerがあります(下のスクリーンショットを参照)。このテーブルビューには常に正確に3行があり、クリックするとこれらの行が展開されて詳細情報が表示されます。テーブルビューの高さが常にこれらの3行だけを表示し、それ以上表示されないようにするにはどうすればよいですか?スクリーンショットでわかるように、コンテンツのない空の行が表示されています。

展開された行には、UILabels以外のビューが含まれる場合があることに注意してください。

IBでの表示は次のとおりです。

ここに画像の説明を入力してください

4

6 に答える 6

5

このようなものが必要だと思います

//Return number of rows in section
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    [self setTableHeight];
    return 3;
}

//Method which lets you calculate the height of tableView depending on your 3 cells
- (void)setTableHeight
{

    if(_isRowExpanded == NO)
    {
        tableHeightCalculated = rowHeight * 3; // rowHeight use default 44 or ur custom
    }
    else
    {
        //You need to put some logic here to Calculate or put approx height of  Expanded_Row_Height
        tableHeightCalculated = rowHeight * 2 + Expanded_Row_Height;

        if(tableHeightCalculated > maxHeightAllowed) //maxHeightAllowed is your current table height in snapshot
        {
            tableHeightCalculated = maxHeightAllowed;
        }
    }
    tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y,
                                 tableView.frame.size.width,  tableHeightCalculated);
}
于 2012-10-10T17:34:29.253 に答える
0

このfooterviewメソッドを追加します。これは機能します。これにより、空のセルが削除されます。

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, 0)];
v.backgroundColor = [UIColor clearColor];
[tableView setTableHeaderView:v];
[tableView setTableFooterView:v];
return v;
}
于 2012-10-10T14:52:07.227 に答える
0

frameプログラミングで操作したい任意のコントロールのプロパティを使用します。frameはさらに と の 2 つの性質を持っていsizeますorigin。プロパティを使用してsize幅と高さを操作し、 を使用してコントロールのorigin操作xyプロパティを操作できます。必要なことは、次の方法で実行できます。

CGRect frame = control.frame; //control is your UIControl

frame.size.height = 10.0; //suppose 10 is the desired height.

control.frame = frame;

これがあなたが探しているものであることを願っています。

于 2012-10-10T14:34:51.627 に答える
0

実際のセルを表示するために必要なスペースよりも垂直方向のスペースが大きい場合、UITableView は偽の空のセルを挿入します。この動作を実際に制御することはできません。できることは、テーブル ビューの高さを十分に小さい値に設定することだけです。

于 2012-10-10T14:30:24.143 に答える
0

この 2 行は、テーブルをコンテンツ サイズと正確に一致させたい場合に役立ちます。それは「幻想」ですが、魔法のように機能します。

 self.tableView.tableFooterView = [UIView new];
 self.view.backgroundColor = [UIColor whiteColor];
于 2015-09-09T06:22:37.863 に答える
0

テーブルのフッタービューを初期化してみてください:

TableView.tableFooterView = [[UIView alloc] init];

于 2012-10-10T14:42:03.850 に答える