3

On the iPad, the Grouped style tableview's cells are inset deeper from the edge of the tableview than on the iPhone.

I need to retrieve the Left and Right distances from the edges of the tableview to where the cell begins. What i'm referring to is similar to "Margins". I read the UITableview API up and down and can't find a property that returns this.

I need to use this in calculation to compute where to position content in my cells.

Thanks in advance! Alex

4

2 に答える 2

3

私はこれをテストしていませんが、両方のフレームを選択して、そこから比較できるはずです。

CGRect cellFrame = yourCell.frame;

CGRect tableFrame = yourUITableView.frame;

CGRect値は(x coordinate, y coordinate, width, height)です。

また、次を使用してフレームを印刷することもできます。

 NSLog(@"your cell frame is %@",NSStringFromCGRect(yourCell.frame);
 NSLog(@"your table frame is %@",NSStringFromCGRect(yourUITableView.frame);
于 2013-01-10T03:14:07.727 に答える
1

私はこれを解決するために、iPadのlayoutSubviews呼び出しをオーバーライドし、グループ化されたビューマージンを、明らかに隠された値ではなく、希望する値に設定しました。Stackの他の回答は、幅が10〜45ピクセルの範囲で変化する可能性があることを指摘しています。

In your CustomTableViewCell class
- (void)layoutSubviews
{
    CGRect f = self.bounds;
    f = CGRectInset(f, 10, 0);
    self.contentView.frame = f;
    self.backgroundView.frame = f;
}

contentViewとbackgroundViewをTableCellの幅と同じになるように強制することもできますが、この場合は、グループ化されたビューを少しはめ込む必要があります。また、作業なしで端から端まで移動するカスタムヘッダー/フッタービューとのマッチングを向上させることもできます。

于 2013-01-23T19:30:15.877 に答える